I'm trying to make my actor switch between tow images so it looks like it's moving but I can't get it to work.
private GreenfootImage image1; private GreenfootImage image2; public static int speedOverTime = 0; public int health = 5; public void act() { movement(); damage(); speedTime(); speedOverTime++; image1 = new GreenfootImage("EvilCrabLeft.png"); image2 = new GreenfootImage("EvilCrabRight.png"); setImage(image1); walkAnimation(); } /** * */ public void walkAnimation() { if(getImage() == image1) { setImage(image2); } else { setImage(image1); } }
public static int speedOverTime = 0; private GreenfootImage image1; private GreenfootImage image2; public int health = 5; private int animTimer; private int animFrames = 8; public EvilCrab() { image1 = new GreenfootImage("EvilCrabLeft.png"); image2 = new GreenfootImage("EvilCrabRight.png"); setImage(image1); } public void act() { movement(); damage(); speedTime(); speedOverTime++; walkAnimation(); } public void walkAnimation() { animTimer = (animTimer+1)%animFrames; if (animTimer == 0) { if (getImage() == image1) { setImage(image2); } else { setImage(image1); } } }