Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


FPS Limiting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 MrTheFoxx   Members   -  Reputation: 100

Like
0Likes
Like

Posted 09 February 2012 - 03:56 PM

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

while(playing) {
frames++;
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

Sponsor:

#2 zacaj   Members   -  Reputation: 643

Like
0Likes
Like

Posted 09 February 2012 - 04:13 PM

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
SDL_Delay(1000/FPS-timer)
repeat
1000/FPS gives you the time for one frame in milliseconds.  You may want to look into framerate indepentent code later





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS