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

2015/5/23

Animating Sprites when walking

DietrichaLove DietrichaLove

2015/5/23

#
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);
      }
}
danpost danpost

2015/5/23

#
I do not see how any movement could come from this. Either this is not your exact class code or it would not compile. There are syntax errors, exceptions, and no act method as shown.
You need to login to post a reply.