Sign in to follow this  
NighTiger

Slow down

Recommended Posts

I guys, I have a function like this
void fps(void)
{
  now = SDL_GetTicks() / 1000;

  if (now - old_fps == 1)
  {
    sprintf(string, "Salvatore Di Fazio - fps: %i", count_fps);
    SDL_WM_SetCaption(string, "Salvatore Di Fazio");
    count_fps = 0;
  }
  else
   count_fps++;

  old_fps = now;
}
How can I use this function to slow down, about 60 fps, my game? tnx

Share this post


Link to post
Share on other sites
You could set up your game logic to keep a running tally of the fps.... In your game loop, just before the render, check to see if the current fps is equal to or less than 60.... If it is, render and set the fps back up to a ridiculous level, otherwise, keep processing data.

Share this post


Link to post
Share on other sites
Usually, in Win32, I'd basically just check to see at the beginning of the game loop if 1/60th of a second has passed. If so, process and render. If not, then Sleep(0) to give up your time slice and try it again next time around. This has the benefit of locking your app at 60fps, which makes things manageable, and also doesn't suck down CPU time waiting for the next frame.

Of course, the best way to do it from a gameplay viewpoint is just to do all your calculations taking the current frame delta into account. But that's a lot harder.

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