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

2016/7/21

how do i set a timer

Trevlodown Trevlodown

2016/7/21

#
I have made a game where there is a blue car and a bus the blue car needs to escape the bus but i need a timer so that when it runs out if the blue car is still alive the game ends and blue wins
private int timer = 60;
    if (timer>0)
    {
        timer--;
        if(timer == 0) Greenfoot.stop();
    }
That what i have for the timer but its not working
Super_Hippo Super_Hippo

2016/7/21

#
Place lines 2 through 6 into the act-method. By the way, you should probably use a higher number than 60 because 60 act-cycles is about one second at normal speed.
You need to login to post a reply.