Skip to main content
gamedev.net
🔒 Locked

Timer stuff

Started by Nokame Oct 12, 2006 at 11:14 PM 3 replies 550+ views
Original Post
Nokame
Nokame
so i'm trying to base my animation off a timer... right now the SetTimer() Windows API function is what i'm using... is there a better timer? or better way to set up your animation? should i do it by pixels moved? I'm working with directdraw right now... on a 2d rpg style game. The timer is always running, and all the characters on the screen are running off one timer (is that dumb?) also... the way it works is once i start moving the player, it begins to animate... i mean its straight forward... so i just need a few ideas... SetTimer doesnt seem to be a very good timer.
Colin Jeanne
Colin Jeanne
The resolution for window timers (that is, those set by SetTimer()) is pretty low. I've had less than stellar experience with using them in games. Many games will incorporate timing into their main loop along the lines of

while (true) {   if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {      TranslateMessage(&msg);      DispatchMessage(&msg);   } else {      // Handle game processing   }}


This code makes the game process game events (such as animations) whenever there is nothing pending in the message queue. This will also make your game use a large amount of CPU. In my showcase entry I had game processing in a different thread. The thread was pretty much a while loop and it would sleep after processing to make sure that the CPU wasnt completely eaten.
Specchum
Specchum
For whatever it's worth I'm using the ctimer class for my timer functions (and using it for animations) and it works well enough. I could have used the QueryPerformanceCounter for greater resolution but that would have lost me cross-platform compatability.
"There is no dark side of the moon." - Pink Floyd
Nokame
Nokame
i'm sorry, but i dont see where the timer is in your code :), i have my game running in the main while loop as well. I'm not sure what were trying to explain to me, i'm pretty new to game programming... this is my first game. i mean it looks good, i have good collision detection and good animations and direction, and all that good stuff... but the timer seems to be off... and i just need a more accurate way to animate the characters/shooting/player/whatever else i decide to animate.... if you want, it would be cool if you could explain what you meant. sorry for my lack of knowledge :).
Colin Jeanne
Colin Jeanne
In the game loop example that I have there is no timer. Time passes as the program gets executed - how much time passes doesnt really matter. When the program has the ability to draw a new frame it does. What you will need is the ability to know how much time elapsed and for that you can use timeGetTime() or something.

If instead you meant my showcase entry, then there is no timer there either. The thread which controls the game logic simply runs in a loop. When it finishes a cycle it starts the next and draws a new frame.

Topic Locked

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

Sign in to reply to this topic.