I want to use an int timer for jumping animation (see the example of wished result in jabka.wip on my page, precisely on the jump to the left (I used delay() there, which now I want to avoid). However, the timer doesn't work at all. Any ideas of how to fix it?
public class Jabka extends Actor
{ private int a;
private int ticker=1000; //instead of delay
private int timer=0; //for jumping animation
private boolean facingLeft=false;
private int ground=350;
private boolean idle=true;
public void act(){
String key=Greenfoot.getKey();
if(key != null && key.equals("d") && idle)jumpRight();
if(key != null && key.equals("a") && idle)jumpLeft();
if(Greenfoot.isKeyDown("s"))dive();
if(Greenfoot.isKeyDown("w") && idle) strike();
if(!Greenfoot.isKeyDown("s") && !Greenfoot.isKeyDown("w") && !idle) rest();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void jumpRight(){
turn(-90);
a = getX();
setImage("jabka.skin.2.png");
while (timer<36){
if (getX()<=595){
if(ticker > 0) ticker--; else{
turn(5);
move(4);
timer++;
ticker=200;
}
}else{
setLocation(0,getY()-50);
a = getX()-100;
setRotation(45);
timer+=28;
}
}
turn(-90);
setRotation(0);
setLocation(a+100,ground);
setImage("jabka.skin.1.png");
timer=0;
facingLeft=false;
}
public void jumpLeft(){
turn(90);
a = getX();
setImage("jabka.skin.2.png");
getImage().mirrorHorizontally();
while (timer<36) {
if (getX()>=1){
turn(-5);
move(-4);
Greenfoot.delay(1);
timer++;
}else{
setLocation(600,getY()-50);
a = getX()+100;
setRotation(-45);
timer+=28;
}
}
setRotation(0);
setLocation(a-100,ground);
setImage("jabka.skin.1.png");
getImage().mirrorHorizontally();
timer=0;
facingLeft=true;
}
