I have a question about some of the code involved using a fixed time step. Here is some example code:
const float TimePerFrame = 1 / 60.0f;
sf::Time timeSinceUpdate = sf::Time::Zero;
while ( window.isOpen() )
{
sf::Time elapsed = clock.restart();
timeSinceUpdate += elapsed;
while ( timeSinceUpdate > TimePerFrame )
{
timeSinceUpdate -= TimePerFrame; // This is the part I don't understand. Why do this?
handleEvents();
update( TimePerFrame );
}
render();
}
I don't understand why you do the line that I commented? Also, is this code suppose to run the game at 60 fps? Because when I run it, the frame rate is over 9000. Sorry if it's a very simple question, but maybe I'm over thinking it and don't see something obvious. Thanks.