I have a stick man actor in my World and I need it to animate between 6 frames. I might just be missing one simple and silly thing but I am struggling to figure it out myself. This is the code for the actor I want to animate:
Any and all help is appreciated, thank you.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Man extends Actor
{
private GreenfootImage runF1 = new GreenfootImage("RunManF1.png");
private GreenfootImage runF2 = new GreenfootImage("RunManF2.png");
private GreenfootImage runF3 = new GreenfootImage("RunManF3.png");
private GreenfootImage runF4 = new GreenfootImage("RunManF4.png");
private GreenfootImage runF5 = new GreenfootImage("RunManF5.png");
private GreenfootImage runF6 = new GreenfootImage("RunManF6.png");
/**
* Constructor for the "Man" object.
*/
public Man()
{
setImage(runF1);
}
/**
* Act - do whatever the Man wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
animate();
}
/**
* Animate this character.
*/
public void animate()
{
if(getImage() == runF1)
{
setImage(runF2);
move(1);
}
else if(getImage() == runF2)
{
setImage(runF3);
move(1);
}
else if(getImage() == runF3)
{
setImage(runF4);
move(1);
}
else if(getImage() == runF4)
{
setImage(runF5);
move(1);
}
else if(getImage() == runF5)
{
setImage(runF6);
move(1);
}
else if(getImage() == runF6)
{
setImage(runF1);
move(1);
}
}
}