Hey, I would like to add a delay on the image switch of my player in my game, without changing the speed of the player moving. Below is the code for the image switching and the code for the actor that extends class which contains the changeDirection method. A delay that slows the image switch that makes it more realistic would be greatly appreciated. Thx for the help.
public class AnimatedActor extends InteractiveMover
{
private GreenfootImage images;
private int currentImage = 0;
/**
* Construct an animated actor. This assumes that you have provided image
* file (in the 'images' folder) named 'basenameN.suffix', where N is
* .
*
* @param basename The base name of the image files.
* @param suffix The suffix of the image files (must include the ".").
* @param noOfImages The number of images to be use din the animation.
*/
public AnimatedActor(String basename, String suffix, int noOfImages)
{
changeDirection(basename, suffix, noOfImages);
}
/**
* Act - do whatever the AnimatedActor wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
currentImage = (currentImage + 1) % images.length;
setImage(images);
}
public void changeDirection(String basename, String suffix, int noOfImages)
{
images = new GreenfootImage;
for(int i=0; i < noOfImages; i++) {
images = new GreenfootImage(basename + i + suffix);
}
setImage(images);
}
}
//Separate Class
public class Player1 extends AnimatedActor
{
public Player1()
{
super("Space_Man_right_",".png",2);
}
public void act()
{
super.act();
processKeys();
}
public void moveLeft()
{
super.moveLeft();
changeDirection("Space_Man_left_",".png",2);
}
public void moveRight ()
{
super.moveRight();
changeDirection("Space_Man_right_",".png",2);
}
}

