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

2013/9/29

Making the game sleep

mattjames mattjames

2013/9/29

#
How do I make the game sleep for 20 seconds. I used Thread.sleep(20000); but it gave me "unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
JetLennit JetLennit

2013/9/29

#
Try
Greenfoot.delay(200);
davmac davmac

2013/9/30

#
It's easiest to use Greenfoot.delay(...) as JetLennit says, although it will delay by the given number of cycles which depends on the scenario speed. If you need exactly 20 seconds, you can do:
try {
    Thread.sleep(20000);
}
catch (InterruptedException ie) { }
mattjames mattjames

2013/9/30

#
How long would 20 seconds be normal cycles???
SPower SPower

2013/9/30

#
Well, considering an average cycle per second is about 62, so 20.000/62 is about 323
danpost danpost

2013/9/30

#
What I would infer from davmac's reply is that Greenfoot.delay will count act cycles while Thread.sleep will use the system clock (in milliseconds).
SPower SPower

2013/9/30

#
I thought mattjames asked what 20.000 milliseconds was in greenfoot cycles
Kartoffelbrot Kartoffelbrot

2013/9/30

#
I think SPower is right.
danpost danpost

2013/9/30

#
Yes, you are right. He did ask. But now I wonder about the math. 20 seconds at 62 frames per second is 1240 frames. What SPower gave was twenty times milliseconds per frame (not frames per second).
SPower SPower

2013/9/30

#
Why do I always do those little things too fast so it's wrong?! Thanks danpost, and sorry for my mathematical error :(
mezboycalday mezboycalday

2013/10/1

#
jonesy la help me please reply asap
You need to login to post a reply.