View Full Version : timer

06-10-2004, 07:13 PM
i have an image, and i want to move it, say 1 unit per second, using
how can implement a timer function, i tried with the ones in nehes page but they didnt work

06-10-2004, 09:47 PM
rather that a timer, why not use the time between frames as a global step?

// stuff for the timeGetTime() function
// assumes windows platform
#include <mmsystem.h>
#pragma comment( lib, "winmm" )

// globalTime in milliseconds
DWORD globalTime = 0;


void everyFrame() {

// don't let the first frame be too excessive
static bool first = true;
if( first ){
first = false;
globalTime = timeGetTime() - 30;

DWORD time = timeGetTime();
DWORD delta = time - globalTime;
globalTime = time;

// some function that updates everything
// to convert this to a float time in seconds,
// divide it by 1000.0
updateEverything( delta );
}timeGetTime() is not the best time function in the world, but it's not a bad start.

timers are not bad things, but you may find that this method is far more flexible.

06-11-2004, 10:00 AM
thanks that helped