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

2013/10/29

Animation delays

Bmerberg Bmerberg

2013/10/29

#
Hey, I want to animate a seal image popping in and out of the ice, however I cannot put a delay on it without Greenfoot.delay, which stops the entire program. I wan him to pop out, stay as that image for a random amount of time, then disappear for a random amount of time again. Thanks.
MatheMagician MatheMagician

2013/10/29

#
It would help if you shared the code you already have... But if you want to wait several act cycles before performing an action, you can do this: First create a variable
int time = 0;
Every act cycle, increment that value, and check it to see if you want to change the image.
time++;
int delay = 5;//how long you want to wait before chaging the image
if(time%delay==0)
{
      //change image
}
This will call the animation code every five act cycles. Change "delay" to make that time shorter or longer.
You need to login to post a reply.