Im trying to make my character cast a fishing rod and play a casting animation when I press the "f" key but the animation isn't playing and I don't know why. Heres my code for the animations:
private int speed = 5;
GreenfootImage idleRight = new GreenfootImage;
GreenfootImage idleLeft = new GreenfootImage;
GreenfootImage cast = new GreenfootImage;
String facing = "right";
SimpleTimer animationTimer = new SimpleTimer();
public Fisherman()
{
for (int i = 0; i < idleRight.length; i++)
{
idleRight = new GreenfootImage("images/idleAni/idle" + i + ".png");
idleRight.scale(100,80);
}
for (int i = 0; i < idleLeft.length; i++)
{
idleLeft = new GreenfootImage("images/idleAni/idle" + i + ".png");
idleLeft.mirrorHorizontally();
idleLeft.scale(100,80);
}
animationTimer.mark();
setImage(idleRight);
}
int imageIndex = 0;
public void idle()
{
if(animationTimer.millisElapsed() < 500)
{
return;
}
animationTimer.mark();
if(facing.equals("right"))
{
setImage(idleRight);
imageIndex = (imageIndex + 1) % idleRight.length;
}
else
{
setImage(idleLeft);
imageIndex = (imageIndex + 1) % idleLeft.length;
}
}
public void cast()
{
if (Greenfoot.isKeyDown("f"))
{
cast = new GreenfootImage("images/castAni/cast0.png");
cast.scale(100,80);
cast = new GreenfootImage("images/castAni/cast1.png");
cast.scale(100,80);
cast = new GreenfootImage("images/castAni/cast2.png");
cast.scale(100,80);
cast = new GreenfootImage("images/castAni/cast3.png");
cast.scale(100,80);
cast = new GreenfootImage("images/castAni/cast4.png");
cast.scale(100,80);
}
}
public void fish()
{
cast();
}