I'm trying to quickly change the actor image, to create an animation for my act. However, whenever it runs, it only shows the change to the final image, as opposed to cycling through each image.
public class Knight extends Actor
{
private int y=0;
private int x=0;
private int hitpoints=200;
private int delay=20;
private static GreenfootImage knight1 = new GreenfootImage("KnightArm1.fw.png");
private static GreenfootImage knight2 = new GreenfootImage("KnightArm2.fw.png");
private static GreenfootImage knight3 = new GreenfootImage("KnightArm3.fw.png");
private static GreenfootImage knight4 = new GreenfootImage("KnightArm4.fw.png");
private static GreenfootImage knight0 = new GreenfootImage("KnightArm0.fw.png");
public Knight()
{
}
public void act()
{
move();
if(Greenfoot.isKeyDown("space") && delay<0)
{
attack();
delay=20;
}
else
{
delay=delay-1;
}
}
public void move()
{
y=getY();
x=getX();
if(Greenfoot.isKeyDown("w"))
{
y=y-4;
setLocation(x,y);
}
if(Greenfoot.isKeyDown("a"))
{
x=x-4;
setLocation(x,y);
}
if(Greenfoot.isKeyDown("s"))
{
y=y+4;
setLocation(x,y);
}
if(Greenfoot.isKeyDown("d"))
{
x=x+4;
setLocation(x,y);
}
}
public void attack()
{
long start=System.currentTimeMillis();
long curTime=System.currentTimeMillis();
do{
curTime=System.currentTimeMillis();
}while(curTime-start<100);
arm1();
start=System.currentTimeMillis();
do{
curTime=System.currentTimeMillis();
}while(curTime-start<1000);
arm2();
start=System.currentTimeMillis();
do{
curTime=System.currentTimeMillis();
}while(curTime-start<1000);
arm3();
start=System.currentTimeMillis();
do{
curTime=System.currentTimeMillis();
}while(curTime-start<1000);
arm4();
start=System.currentTimeMillis();
do{
curTime=System.currentTimeMillis();
}while(curTime-start<1000);
arm3();
start=System.currentTimeMillis();
do{
curTime=System.currentTimeMillis();
}while(curTime-start<1000);
arm2();
start=System.currentTimeMillis();
do{
curTime=System.currentTimeMillis();
}while(curTime-start<1000);
arm1();
start=System.currentTimeMillis();
do{
curTime=System.currentTimeMillis();
}while(curTime-start<1000);
setImage(knight0);
}
public void arm1()
{
setImage(knight1);
}
public void arm2()
{
setImage(knight2);
}
public void arm3()
{
setImage(knight3);
}
public void arm4()
{
setImage(knight4);
}
}
