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

2015/12/23

time countdown affected by speed of game/computer speed/framerate

rsvohra rsvohra

2015/12/23

#
So basically, when I move the speed bar, it affects how fast the time counts down. how can i fix this? my timer code: int timeleft = 60; private int timer = 3600; public void act() { if (timer>0) { timer--; if (timer % 60 == 0) { timeleft--;; } } if(timer == 0) { Greenfoot.stop(); } showText (timeleft + "", 500, 344); }
Super_Hippo Super_Hippo

2015/12/23

#
You can use the 'System.currentTimeMillis' and then use the difference when calling it again. But you should only use it if you want to create a clock of something, not when limiting time in a game.
fejfo fejfo

2015/12/23

#
or import the Timer class
rsvohra rsvohra

2015/12/24

#
@fejfo what timer class?
danpost danpost

2015/12/24

#
I believe it is actually called the SimpleTimer class. You can import it into your scenario using the menubar -- "Edit>Import class...".
You need to login to post a reply.