I am having trouble with getting my animations to work while my characters are moving. I have a player, who will run right and left. When he starts to run either direction, the animation starts, and stops after about 1 second then wont start again unless I let go of the run button and press it again. The zombies will only translate across the screen until they reach their destination then they will stand in place and animate. I need them to animate and translate simultaneously. Can anyone spot the error? I had this working before I cannot figure out how I messed it up!
public NinjaSprite(ImagesLoader im, String name, int p) {
super(Variables.pWidth/2, 0, Variables.pWidth, Variables.pHeight, im, name);
setStep(5,0);
locy = Variables.pHeight/2 + 25;
period = p;
} // end of ninja sprite
public void moveLeft()
/* Request that the sprite move to the left. It doesn't
actually move, but changes its image and status flags. */
{ setImage("leftPlayer");
System.out.println("player period: " + period);
loopImage(period, DURATION); // cycle through the images
isFacingRight = false; isStill = false;
super.updateSprite();
}
public void moveRight()
/* Request that the sprite move to the right. It doesn't
actually move, but changes its image and status flags. */
{ setImage("rightPlayer");
loopImage(period, DURATION); // cycle through the images
isFacingRight = true; isStill = false;
super.updateSprite();
}
public void stayStill()
/* Request that the sprite stops. It stops the
image animation and sets the isStill status flag. */
{ stopLooping();
isStill = true;
}
public class Zombie extends Sprite{
private String zName;
public Zombie(int x, ImagesLoader imsld, String name, int p){
super(Variables.pWidth/2, 0, Variables.pWidth, Variables.pHeight, imsld, name);
period = p;
locx = x;
zName = name;
setStep(1,0);
System.out.println("zombie period " + period);
}
public void move(int target){ // zombies attempt to move towards the player
if(locx > target){
this.setImage(zName);
locx -= Variables.zombieSpeed;
loopImage(period, DURATION); // cycle through the images
}
else if(locx < target){
this.setImage(zName);
locx += Variables.zombieSpeed;
loopImage(period, DURATION); // cycle through the images
}
} //end of updateSprite
}