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

2017/11/30

countdown

doglover555 doglover555

2017/11/30

#
how do I make a simple countdown that i can call in the act() method of Countdown by making a method called setCount() within the Countdown class? i think it would be best to use a for loop, but i'm not sure if that's the most convenient way. just leading me in the right direction would be a great help, thanks.
Super_Hippo Super_Hippo

2017/11/30

#
Do not use a for loop. The act method is called each 'act cycle'. You can think of it as a loop which is executed once, then each other actor (and the world) is also doing its act method loops and then it starts all over (as long as the actor is in the active world). So if you have this:
1
2
3
4
5
6
private int timer = 1000;
 
public void act()
{
    timer--;
}
The timer will be decreasing from 1000 over time.
doglover555 doglover555

2017/11/30

#
How do I edit the frame rate to make it count down in seconds? And then should I use an if statement to stop it when it gets down to zero?
Super_Hippo Super_Hippo

2017/11/30

#
With speed 50 (speed slider in the middle), one second is about 55 act cycles, so you could count it as it is and when displaying, you divide it by 55. And stopping at 0 makes sense if you don't want a negative time. You could stop the scenario at 0 or do whatever should be done when the time is over.
You need to login to post a reply.