Skip to main content
GameDev.net gamedev.net
🔒 Locked

controlling game speed

Started by m00se123 May 24, 2002 at 6:36 PM 4 replies 200+ views
Original Post
m00se123
m00se123
Im making a snake game and i need some help figuring out how to control the snake speed, and make it the same speed on all machines. i want the snake to move a couple times every second, or something like that, but i need a function to measure time less than 1 second. i think i could then test the time twice, subtract them, and see if the diff is a certain amount and if it is move the snake. does this sound about right. thanks for the help Jesse
Metal Typhoon
Metal Typhoon
why not move 1.5 or twice faster other than calculating the move and the 1 second ?
Metal Typhoon
Blacksmith_Tony
Blacksmith_Tony
The way you have outlined will work. You get one time just before the test and the other after you have moved the snake
(but still within the if statement, so it only updates if you move the snake).

You can use either timeGetTime(), or performance counters (and probably other ways as well). Both of these have resolutions less than 1 second.
m00se123
m00se123
what library is timeGetTime() in. Also what are performance counters.
Blacksmith_Tony
Blacksmith_Tony
timeGetTime() is in winmm.lib if I remember correctly. As for performance counters do an MSDN search for QueryPerformanceCounter and QueryPerformanceFrequency, I think thats all you''ll need. Performance counters have a greater resolution, but are a bit harder to use. I expect timeGetTime will be enough for what you want.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.