Timer for platform game
Monkey Forums/Monkey Programming/Timer for platform game
| ||
Is there an easy was of implementing a timer into my platform game? |
| ||
What do you mean by a timer? A record of how long the level took, or a time limit counting down? Anyway, the basic code for either, in your game update, can look something like this:Method Update:Void() timePassed = Millisecs() - lastMillis lastMillis = Millisecs() If Not paused secondsPlayed += timePassed * 0.001 End End |
| ||
Basically a timer in the top corner which counts down from say 400 seconds, but also a way of pausing for when the player pauses it. |
| ||
You should search this forum for information related to delta time. The example above is a kind of version of this. This example is a more expanded one https://github.com/Regal-Internet-Brothers/deltatime https://www.google.com/search?q=site%3Awww.monkey-x.com%2F+delta+time Once you have deltatime tracking working then you can accurately count down from 400 seconds. When you have your game in "paused" then don't subtract the deltatime from the time left. For displaying your timer, you could use monkey's drawtext or to add support for a pixel font. Search forum for that too. |