Computer Science Canada Time Remaining count down |
Author: | vassosman [ Sat Jun 14, 2008 10:59 am ] |
Post subject: | Time Remaining count down |
can some body please tell me or send me to a link on how to have a countdown or time remaining on my game thank you in advanced |
Author: | Tony [ Sat Jun 14, 2008 1:12 pm ] |
Post subject: | RE:Time Remaining count down |
time_allowed - (current_time - start_time) = time_remaining |
Author: | Stove [ Sat Jun 14, 2008 1:46 pm ] | ||||
Post subject: | Re: Time Remaining count down | ||||
There are probably a couple ways to make a countdown timer. One way you could do it, is to make a loop with a delay, and increment a counter variable each time. Something like:
The only problem with that method is that delay() blocks the program while it waits, which means nothing else on that process will be able to run while your counter is counting down. So for example you wouldn't be able to update the screen (more than the delay value) and run the countdown at the same time. So a better method would be to use Time.Elapsed to find the amount of time (in milliseconds) that has passed each time a loop is run. So something like:
This way is non-blocking, so you can update the screen and have other things happening while the countdown runs. You can also use this method to achieve a steady frame rate on a game by having it fire a game procedure at a set interval. One last thing, just remember to use greater than or equal to (>=) and not just equal to (=) when comparing the "now" and "last" variables, because "now - last" may not always hit 1000 directly. Anyways, hope that answers your question. Edit: Opps, Tony beat me to it ![]() |
Author: | Insectoid [ Sun Jun 15, 2008 12:53 pm ] | ||
Post subject: | RE:Time Remaining count down | ||
I think a counter would be a better idea. Time.Elapsed does not account for a computer's processor speed. So on my computer at home, I could do twice as much in the same Time.Elapsed as on the crappy school computers. A counter will always be the same speed as the program. Oh wait...stove seems to have combined the methods...Though it does not look like it will acount for lag.
|
Author: | Tony [ Sun Jun 15, 2008 1:29 pm ] |
Post subject: | Re: RE:Time Remaining count down |
insectoid @ Sun Jun 15, 2008 12:53 pm wrote: Time.Elapsed does not account for a computer's processor speed.
That's kind of the point to not have your CPU bend the space-time continuum. ![]() Time.Elapsed will give you the time, as in the time on your watch. A counter will count the frames of the loop. |
Author: | andrew. [ Mon Jun 16, 2008 11:33 am ] |
Post subject: | RE:Time Remaining count down |
Haha, space-time continuum. Anyways, yeah, use the way that Stove said. That way is better then delays because it doesn't stop the rest of your program. |