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

2015/3/26

Help- Simple Timer

Leenza Leenza

2015/3/26

#
I want to create a timer in my game. The idea is that the hero must collect points by collecting things on the screen and gaining points. If the hero does not collect a certain number of points (haven't decided on the number yet) in a certain amount of time (haven't decided on time length either), then they lose the game. I have to use the simple timer class that you can import, as it is a requirement though (This is for an assignment at school). Does anyone know how I can do this?
danpost danpost

2015/3/26

#
Because the SimpleTimer class uses the system clock (real time) for timing, you cannot just start the timer (call the 'mark' method) in the world constructor or even in the Hero constructor. Best may be to override the 'started' and 'stopped' methods of the World class to control the timer -- start it in the 'started' method and stop it and record the current game time (use an int field to add all partial game times together) in the 'stopped' method. Make sure that you add this field value to the running game time together when comparing to total time limit for game.
Leenza Leenza

2015/3/26

#
danpost wrote...
Because the SimpleTimer class uses the system clock (real time) for timing, you cannot just start the timer (call the 'mark' method) in the world constructor or even in the Hero constructor. Best may be to override the 'started' and 'stopped' methods of the World class to control the timer -- start it in the 'started' method and stop it and record the current game time (use an int field to add all partial game times together) in the 'stopped' method. Make sure that you add this field value to the running game time together when comparing to total time limit for game.
I not quite sure what you mean by this. Could i not just start the timer as soon as the game starts and then end it after a certain amount of time. Then compare the timer to the point and if the points equal or are above what i want (In an if statement or something like that) then the player could move on to the next level or win the game. If not they lose. Also I reread theassignment sheet and it does not specifically say th use the simple timer class, we just have to show we know how to use timers. So if there is another way that is easier, i suppose that could work as well.
danpost danpost

2015/3/26

#
A game timer can work in one of two ways -- it can track actual time or it can track game act cycles (frames). Either way, you will need an instance field of int type in your world subclass. If tracking frames, the act method of that class should increment the value of the field unconditionally, then check its value for game limit (usually, scenarios run between 50 and 60 frames per second; so, for example, a two-minute game would be limited to between 6000 and 7200 acts).
You need to login to post a reply.