I am trying to make a rpg game in which it has animated walking. It is suppose to cycle through a set of images, but what it ends up doing is going from one side of the screen to the other in less than a second.
import greenfoot.*;
public class Avatar extends Actor
{
if(Greenfoot.isKeyDown("right"){
setImage("NameOfImage");
move(1);
setImage("AnotherImage");
move(1);
setImage("AnotherImage");
move(1);
}
if(Greenfoot.isKeyDown("left"){
setImage("NameOfImage");
move(-1);
setImage("AnotherImage");
move(-1);
setImage("AnotherImage");
move(-1);
}
if(Greenfoot.isKeyDown("up"){
setImage("NameOfImage");
setLocation(getX(),getY()-1);
setImage("AnotherImage");
setLocation(getX(),getY()-1);
setImage("AnotherImage");
setLocation(getX(),getY()-1);
}
if(Greenfoot.isKeyDown("down"){
setImage("NameOfImage");
setLocation(getX(),getY()+1);
setImage("AnotherImage");
setLocation(getX(),getY()+1);
setImage("AnotherImage");
setLocation(getX(),getY()+1);
}
}
