SFML community forums

Help => General => Topic started by: cybersnap on March 17, 2015, 02:29:04 pm

Title: I would like to understand this game loop please if someone can explain!
Post by: cybersnap on March 17, 2015, 02:29:04 pm
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;
    }
}
 
Title: Re: I would like to understand this game loop please if someone can explain!
Post by: Laurent on March 17, 2015, 02:55:16 pm
There are complete tutorials about fixed timestep, like this one:
http://gafferongames.com/game-physics/fix-your-timestep/