Archived

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

calculating and locking to a certain FPS

This topic is 6390 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 need a bit of information about calculating FPS and also locking to it. i have an idea about the locking, but i need to know the algorithm to calculate it. that''s one of the few things i overlooked in my game development self-training... ;-) thanks for any help, david

Share this post


Link to post
Share on other sites
You probably don''t want to lock the rendering code to a certain FPS, (let''s say 20fps for example).. what you really want to do is let the game draw as fast as it can, and only lock the sprite animation to a specific FPS (assuming your game is 2D). So the game might be drawing at 35fps but the sprites are only animating at 20fps. I personally used 12fps for the sprites in my game.

If you are using animated sprites, the part that decides to move to the next frame of animation has to be seperated from the part that draws the actual image.

For example:

UpdateAllSprites()
RenderAllSprites()

The UpdateAllSprites will check the fps, decide whether it needs to advance the animation frames, and move the character a bit.

The RenderAllSprites will draw the sprites in their current state.

Hope this helps a bit - when I get home I''ll post up some code that give you an idea.

Clay

Share this post


Link to post
Share on other sites
heres my fps code for my opengl game. ticks = milliseconds since program start

if ( ticks >= counter.current + 1000 ) {
counter.last = counter.current;
counter.current = ticks;
counter.delay = counter.current - counter.last;
counter.fps = (counter.frames * 1000) / counter.delay;
counter.frames = 0;
}

Share this post


Link to post
Share on other sites
okay. think about what the abbreviation "FPS" means. frames per second. frames/second. delving into the murky confines of elementary school algebra, we find out that (a*b)/(c*b) = a/c. therefore, we can change this equation to use the total amount of time elapsed since the start of the main loop. now it becomes total_frames / total_time_elapsed. aand, here comes the code:

            
...
int start_time = clock();
int frames = 0;
float fps;

while (!bQuit)
{
int current_time = clock();
fps = (float)frames / (float)((current_time - start_time) * CLOCKS_PER_SEC);
frames++;

...
}




--
Float like a butterfly, bite like a crocodile.


Edited by - goltrpoat on June 19, 2000 4:45:47 AM

Share this post


Link to post
Share on other sites