Hello world! I'm trying to animate a sprite with three images making four frames. I want the variable "cycle" to cycle 0, 1, 2, 1, 0, 1... and so on. However, it seems to go 0, 1, 2, 1, 2, 1, 2, 1 and so on, and I can't figure out why for the life of me! I believe I've posted all the relevant code below--apologies that it's a bit messy. I'd greatly appreciate any help I could get. Thank-you!
private void animate()..
{
if (Greenfoot.isKeyDown("left")){
setImage (new GreenfootImage("PicklesLeft"+(cycle+1)+".png"));
if (cycle == 0){
if (delay < 20){
delay ++;
}
else {
step = true;
cycle = 1;
delay = 0;
}
}
else if ((cycle == 1) & (step = true)){
if (delay < 20){
delay ++;
}
else {
delay = 0;
cycle = 2;
}
}
else if ((cycle == 1) & (step = false)){
if (delay < 20){
delay ++;
}
else{
delay = 0;
cycle = 0;
}
}
else if (cycle == 2){
if (delay < 20){
delay ++;
}
else{
delay = 0;
step = false;
cycle = 1;
}
}
}
}
public void act()
{
move();
animate();
}

