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

Author Topic: I would like to understand this game loop please if someone can explain!  (Read 706 times)

0 Members and 1 Guest are viewing this topic.

cybersnap

  • Guest
Ok, this is not specifically a coding question. I borrowed this code snippet from another thread somewhere around here and implemented it. If you look, I added 2 functions (myUPDATE and myDRAW).

My question is this -> in myUPDATE, I change the rotation of a sprite by a fraction, such as 0.05f. Changing this increases and decreases the speed of the rotation. Is this working correctly? I'm not sure I understand how this relates to keeping the framerate constant at 60fps. Please excuse me I've been at this for a long time, so I have never implemented something like this correctly.

My second question is this. Is this considered fixed timestep or variable timestep.
float dt = 1.f/60.f; // Modify this to change physics rate.
float accumulator = 0.f;
bool drawn = false;

while (App.IsOpened())
{
    accumulator += clock.GetElapsedTime();
    clock.Reset();

    while (accumulator >= dt)
    {
        // Physics and gameplay updates.

       myUPDATE();

        accumulator -= dt;
        drawn = false;
    }

    if (drawn)
    {
        sf::Sleep(0.01);
    }
    else
    {
        // Draw everything.

       myDRAW();

        drawn = true;
    }
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
There are complete tutorials about fixed timestep, like this one:
http://gafferongames.com/game-physics/fix-your-timestep/
Laurent Gomila - SFML developer