Decreasing Timer

BlitzMax Forums/BlitzMax Beginners Area/Decreasing Timer

doswelk(Posted 2009) [#1]
I need a little help:

I am trying to work out how to have a timer that stores 10 seconds that will count down backwards when a key is pressed. This timer would need to be real time not based on the games logic speed.

If the same key is pressed again the timer stops.

The code is set to run under superstrict what is the best variable type to store millsecs? Long ? or given the length of time her just an int or float?

Also is a player picks up a power up I want it to add 5 seconds of time back to the timer (but not exceeding the original 10 seconds).

I know this probably easy but for some reason I am stumped.


matibee(Posted 2009) [#2]
Here's one way using Millisecs() and keeping track of delta time (the time between frames)..



If you're moving sprites around the screen and want their movement to be independent of the frame time too, their speed has to be in relation to timeElapsed.

Another, simpler way, is to set up a timer that limits your logic to a fixed frames per second...




doswelk(Posted 2009) [#3]
Thanks for those most useful...