I'd like to create an array for animating an image for my character when he moves. There are a different set of images for moving right, left, up and down. and i would like for the array to be put in the if statement for my character movement.
GreenfootImage[] right = new GreenfootImage[8];
GreenfootImage[0] = new GreenfootImage("ImagePath");
....
...
int right = 0;
int i = 0;
public void animation () {
if(Greenfoot.iskeyDown("right"){
if(right < 20){
right ++;
return;
}
right = 0;
if(i >7) {
i = 0;
}
actor.setImage(right[i]);
}
}