SFML community forums

Help => General => Topic started by: zander24615 on February 02, 2014, 03:17:34 pm

Title: SFML Game Book - Delta Time Question?
Post by: zander24615 on February 02, 2014, 03:17:34 pm
Hi there, I've got a problem understanding the reason for passing the TimePerFrame variable to the update member function of the game class in the following code from chapter 1 of the book:

void Game::run()
{
        sf::Clock clock;
        sf::Time timeSinceLastUpdate = sf::Time::Zero;
        while (mWindow.isOpen())
        {
                sf::Time elapsedTime = clock.restart();
                timeSinceLastUpdate += elapsedTime;
                while (timeSinceLastUpdate > TimePerFrame)  // I understand the fixed time step loop
                {
                        timeSinceLastUpdate -= TimePerFrame;

                        processEvents();
                        update(TimePerFrame); //Mistake?? or Really Needed??
                }

                updateStatistics(elapsedTime);
                render();
        }
}
 

Could someone tell me why this is necessary?? It's defined as a constant never changing value. (.01666.....) Why not just define Game::PlayerSpeed to 1.66666 instead of passing the TimePerFrame value and then multiplying Game::PlayerSpeed by TimePerFrame. Some insight would be greatly appreciated.

Edit:
Sorry forgot Link to full source i'm trying:
https://github.com/SFML/SFML-Game-Development-Book/tree/master/01_Intro/Source (https://github.com/SFML/SFML-Game-Development-Book/tree/master/01_Intro/Source)
Title: Re: SFML Game Book - Delta Time Question?
Post by: AlexAUT on February 02, 2014, 03:22:48 pm
What if you want to change your tick to 1/30.f? Then your player would be moving at half speed if you do not pass the frametime and multiply it. Thats the reason, just to be able to change the tick without problems.

For example on mobile devices you often want to run your game at 1/30.f to save energy.

AlexAUT
Title: Re: SFML Game Book - Delta Time Question?
Post by: zander24615 on February 02, 2014, 03:34:39 pm
ah, thanks. I do suppose that saves time in the long run.