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

2016/3/10

Set certain image when an actor is not moving

God God

2016/3/10

#
public class Person_Stadning extends Actor
{
    boolean stand = false;
    /**
     * Act - do whatever the Person_Stadning wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(Greenfoot.isKeyDown("right")== true)
        {
            setImage("person.2 walking right.png");
            move(4);
        }
        if(Greenfoot.isKeyDown("left")== true)
        {
            setImage("person.2 Walking left.png");
            move(-4);
        }
        if(Greenfoot.isKeyDown("left")== false)
        {
            setImage("person.2 Standing.png");   
        }
        if(Greenfoot.isKeyDown("right")== false)
        {
            setImage("person.2 Standing.png");   
        }
    }    
}
danpost danpost

2016/3/10

#
You can change 'if' to 'else if' on line 15 and just use 'else' on line 20 (remove the following 'if' statements and just execute the 'setImage' command.
You need to login to post a reply.