Sign in to follow this  

FPS Limiting

Recommended Posts

Right now, I have a loop for the game. I'll post some pseudo code to illustrate it.

while(playing) {
if(frames>FPS) frames=0;
if(frames==FPS) {
// All game functions for displaying the player and map and stuff.

Am I going about this the right way? It has really slowed the game down, but there is still a lot of CPU being used. How can I cut down on that the right way? Is this a good way to limit the FPS? Thank you. :3

Share this post

Link to post
Share on other sites
If you do it this way you program will take up all the available CPU time waiting until its time to update the game. Instead, time each frame as it renders, and then subtract this time from how long each frame should take. Pass this value to SDL_Delay(), which informs the operating system it can give that much time to other processes.
start timer
game functions
stop timer
1000/FPS gives you the time for one frame in milliseconds. You may want to look into framerate indepentent code later

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this