Hey, so im having an issue with having something both run an animation and move from a key being down. Either alone run, but together it cant. Any help will be greatly appreciated. It's a rather long code so i'm only going to post the relevant parts.
public void moveRight()
{
setLocation ( getX() + speed, getY() );
}
public void animateRight()
{
int atime = 0;
while (atime < 18)
{
atime++;
setImage("TeemoRight.png");
setLocation ( getX() + speed, getY() );
if (atime == 6){
setImage("TeemoRunRight.png");
}
if (atime == 12){
setImage("TeemoRunRight2.png");
}
if (atime == 18){
atime = 0;
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | private void checkKeys() { if (Greenfoot.isKeyDown( "left" )) { setImage( "TeemoLeft.png" ); moveLeft(); } if (Greenfoot.isKeyDown( "right" )) { moveRight(); animateRight(); } if (Greenfoot.isKeyDown( "up" ) ) { if (onGround()) {jump();} } } |