# a set FPS

This topic is 5416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys: I have this code:
currTime = GetTickCount();
if (currTime >= lastTime + MIN_FRAME_TIME)
{
numFrames++;
if (numFrames > 11)
{
float currentUpdate = currTime;
fps = numFrames / ((currentUpdate - lastUpdate)/1000);
lastUpdate = currentUpdate;
numFrames = 0;
}
lastTime = currTime;
}


I'm trying to get the frames per seconds maintained at 12. my MIN_FRAME_TIME is (1000/12). However, when I calculate the FPS, its averaging around 8fps, 7.994 or something. Any ideas? Thanks!! Jeff King

##### Share on other sites
frame/sec*sec=frame
I'm not so sure but you should have multipied not divide

currentTime=GetTickCount()*0.001f;//value in sec

if(currentTime-lastTime>1/NUMBER_OF_FRAMES_PER_SEC)
{

lastTime=currentTime;
...do smth.....

}

EDIT: This should work fine

##### Share on other sites
its in milliseconds, so don't I need to divide 1000 milliseconds/ fps? to get how many milliseconds per frame

##### Share on other sites
ok, with this:

	currTime=GetTickCount()*0.001f;//value in sec	if(currTime-lastTime>1/12)	{		numFrames++;		if (numFrames > 11)		{			float currentUpdate = currTime;			fps = numFrames / ((currentUpdate - lastUpdate));			lastUpdate = currentUpdate;			numFrames = 0;			}		lastTime=currTime;	}

I'm getting 16 frames per second... any clues??

##### Share on other sites
What is the resolution of GetTickCount? If it only gives the time every 5 ms or so, after 10 ms (2 ticks), it would be to early so it would wait until the next tick, which would be too late.

Just out of curiosity, why do you want to limit the framerate to 12?

• 21
• 13
• 9
• 17
• 13