Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Game Book - Delta Time Question?  (Read 2200 times)

0 Members and 1 Guest are viewing this topic.

zander24615

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
SFML Game Book - Delta Time Question?
« 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
« Last Edit: February 02, 2014, 03:19:25 pm by zander24615 »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: SFML Game Book - Delta Time Question?
« Reply #1 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

zander24615

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: SFML Game Book - Delta Time Question?
« Reply #2 on: February 02, 2014, 03:34:39 pm »
ah, thanks. I do suppose that saves time in the long run.

 

anything