Advertisement

Sleep()

Started by February 03, 2000 01:40 PM
1 comment, last by Macke 24 years, 10 months ago
Hello! I was wondering if you consider the function Sleep() to be a bad way to make a game stop at a certain time (like when showing a sign "New Level") or is there any better way?
If there is a timer already in the game, it would be much better to use. You have to realize that Sleep() may not act like you expect in some situations due to the fact that windows is not, ultimately, a realtime operating system. For instance, if you put Sleep() in a "for" loop, it will calculate how much sleeping has to be done total, sleep for that long, then zip right through the loop however many times you specified ignoring the Sleep() calls. Also, if you use Sleep(), your program pretty much stops dead while waiting for the time to be up. You won''t be able to process things like mouse clicks or letters while waiting, and most people like the option to hit enter or whatever and pop out of the wait screen.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Advertisement
Do something like (pseudocode):

starttime = currenttime
do{
handle keys here...
}while ((currenttime - starttime) < timetowait)
- DanielMy homepage

This topic is closed to new replies.

Advertisement