Archived

This topic is now archived and is closed to further replies.

count fps

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

i''m sorry if my question is to silly, how to count fps (frame per second) ?? i make a simple game in my computer, run in normal speed, but when i run in a P4 Computer my game is boost over than normal speed, how can i make my game run in normal speed in every computer ? Thanks before, best regard, Randy

Share this post


Link to post
Share on other sites
To make your game run at the same speed on any machine, you need to base your movements on time. Each frame, you get the elapsed time since the last frame and move your object accordingly. Let say you have a car that moves 2 pixels per second, then if the elapsed time is half a second then you move the car 1 pixel.

Share this post


Link to post
Share on other sites
Use a timer. Some possibilities for include:

- GetTickCount
- timeGetTime
- QueryPerformanceCounter
- RDTSC

QueryPerformanceCounter is arguably the most effective solution. Search the GameDev forums for more specific information on each of these.

You can use any of these functions once per frame to find the amount of time elapsed since the last frame. This gives you a FPS value.

You can also use the delta (change in) time in physics calculations, which can be more natural than incrimental operations.

Things get more complicated for things like collision response, but for most purposes, the above methods should work fine.

Share this post


Link to post
Share on other sites
u''ll need to use a timer. There are many tutorials (use google ) on creating timers from basic ones to high precision timers. The important detail u''ll get from timers are the duration/delay between frames...

U use this value as a modifier/scale when performing any motion or animation. For instance, if u want an object to move 10units per second, then use the interval value to determine how much to really move the object each frame.

Not sure how to make it clearer but hope thats a start

Share this post


Link to post
Share on other sites
thanks for answer, i already count the elapsed time, and my sprite move based on fps. When fps is 30, i moved the sprite by 4 pixel, when fps is 60, sprite move in 2 pixel.
Something is wrong with sprite whenever run in 60 fps, the sprite move by 2 pixels is not smooth as 4 pixel, i know it''s strange, but how to make the sprite move 4 pixel in fps 30 and fps 60 in same time ??
i,m sorry if my english is bad

best regard,Randy

Share this post


Link to post
Share on other sites
Ive just made 2 fps counters (one using GetTickCount and one using QueryPerformanceCounter) running at once over a load of GL_TRIANGLES. I tested them both with fraps, but there seems to be a problem...

Anything below <100FPS works fine both counters and fraps match up. Anything >100FPS just seems to take longer than a second to add up, and i get like "Frames per 2 seconds", it''s weird.

Anyideas?

Share this post


Link to post
Share on other sites
If you''re mixing floating and fixed point math, make sure you cast the integers to floats correctly. Failing to do so may result in various errors related to incorrect rounding in calculations.

-Nik

Share this post


Link to post
Share on other sites