This site requires JavaScript, please enable it in your browser!
Greenfoot back
Kolyma
Kolyma wrote ...

2018/2/28

Need help for several problems

Kolyma Kolyma

2018/2/28

#
Hello, I'm a student and i have to create my own computer game with the old 2.4.2 version of greenfoot. My game should be similar to the game "falling leaves" - a girl who is running on the bottom and catching fruits which are falling from the sky. I created the following code for the running animation of the girl: public void switchImage() { if (getImage() == image1) { setImage(image2); } else { if (getImage() == image2) { setImage(image3); } else { setImage(image1); } } } my question is how can i slow down the speed of the changing images?
Super_Hippo Super_Hippo

2018/2/28

#
Don't change it every act cycle. So for example changing the image every second act cycle (half speed).
private int imgTimer = 0;

public void switchImage()
{
    if (++imgTimer%2 != 0) return;
    //rest of the method
}
You need to login to post a reply.