This site requires JavaScript, please enable it in your browser!
Greenfoot back
gdrgnxxi
gdrgnxxi wrote ...

2019/5/15

MY ACTOR'S IMAGE IS STRETCHING AS IT FALLS

gdrgnxxi gdrgnxxi

2019/5/15

#
Hello so my object is supposed to fall but as it falls, instead of falling, the image is stretching all the way down :(((
gdrgnxxi gdrgnxxi

2019/5/15

#
HERE IS THE CODE OF THE IMAGE THAT STRETCHES
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Sausage here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Sausage extends Actor
{ 

   public Sausage()
    {
       GreenfootImage image = getImage();
        int myNewHeight = (int)image.getHeight();
        int myNewWidth = (int)image.getWidth();
        image.scale(myNewWidth, myNewHeight); 
    }

    /**
     * Act - do whatever the Cheese wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        fall(); 
        getSau();
        if(getY() == 599) {
                World world;
                world = getWorld();             
                Mustard mus = new Mustard();
                world.addObject(mus,650,15);
            }   
    }   

 
    public void fall() //HINDI SMOOTH
    {
        setLocation(getX(), getY() + 1);
        
        }
        
   public void getSau()
    {
        Actor knife = getOneIntersectingObject(Knife.class);
        if(knife!= null){
         getWorld().removeObject(knife);
         World realWorld = getWorld(); 
            getSau();
            RealGame levelone= (RealGame)realWorld; //accessing the counter every time trash gets hit by knife
            Counter counter = levelone.getCounter(); //get actual counter from the world
            counter.loseScore();
        }
    }    
}
danpost danpost

2019/5/15

#
gdrgnxxi wrote...
Hello so my object is supposed to fall but as it falls, instead of falling, the image is stretching all the way down :(((
Please provide your RealGame class codes.
gdrgnxxi gdrgnxxi

2019/5/15

#
nccb nccb

2019/5/15

#
I think it's not stretching, it's adding lots of new copies. Looking at the code, you add a new Mustard whenever Sausage is at Y 599. But if that's the bottom of the world, Sausage remains there (things cannot fall out of the world by default in Greenfoot) adding a new Mustard every frame. I'm guessing you also need to remove the Sausage at that point using getWorld().removeObject(this). Although looking at the images, there may be a similar problem that the bread is adding lots of sausages -- same principle though.
You need to login to post a reply.