Timer Implementation

Started by
3 comments, last by chollida1 18 years, 12 months ago
I still have not figured out how to do a simple timer in my games yet even after reading a crap load of information on the subject. If anyone could inform me, what is the best way to implement a simple timer?
Gor435 - My Journal - MySpace - Facebook
Advertisement
What exactly do you mean by simple timer? If you're looking for a function that returns the current time check out timeGetTime() and QueryPerformanceCounter() (assuming C++/Win32), otherwise could you be more specific in your question?

Regards
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
I also want to know this.
I need a timer to make the speed of my game consistant. I understand what to do from NeHe's tutorial #21, but is it a good idea to put the timer and any additional timer functions in a seperate class?
im not sure i know what you mean, but simple timing is done like this:
you measure how long time a frame takes, like this: (guess this is what you mean by a timer)
framestart = timeGetTime()
.. render and do all stuff..
frametime = timeGetTime() - framestart

then to calculate, for example motion, you do like this:
newposition = oldposition + speed * frametime

its all simple physics:
s = v * t
(distance = speed * time)
----------Thale Cres
DirectX comes with a good timer. It has nothing to do with DIrectX; its straight win32 so you can use it for any C based graphics language on windows.

It may give you a hand.

Cheers
Chris
CheersChris

This topic is closed to new replies.

Advertisement