Saturday, July 23, 2022
HomeGame Developmentsfml - Does the bee transfer very quick within the very first...

sfml – Does the bee transfer very quick within the very first body of the sport?


If the issue is that the primary time is not dependable as a consequence of variable initialization between creating the clock & studying it, you possibly can add a primary examine that zeros the clock again out on the primary time by your loop:

// notice: earlier code omitted - all of that may keep the identical

Clock clock;
bool firstTimeThrough = true;
whereas (window.isOpen())
{
    /*
    *****************************************
    Deal with the participant's enter
    *****************************************
    */
    if (Keyboard::isKeyPressed(Keyboard::Escape))
    {
        window.shut();
    }
    /*
    *****************************************
    Replace the scene
    *****************************************
    */
    // Measure time
    Time dt = clock.restart();
    if(firstTimeThrough)
    {
         dt = clock.restart();
         firstTimeThrough = false;
    }

    // notice: remaining code omitted - all of that may keep the identical

The documentation for restart says:

This operate places the time counter again to zero. It additionally returns the time elapsed for the reason that clock was began.

On the primary time by (and solely the primary time by), the clock will get reset twice, so the ensuing time ought to both be zero or very near zero. As a result of the firstTimeThrough flag is true on the primary cross by the loop, the remaining iteration ought to behave as ordinary.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments