1
System / Re: [Help] I don't understand sf::Time, sf::Clock
« on: November 28, 2019, 01:18:33 pm »The 'yellow' loop is a way of processing fixed timesteps when frame times even though frame times are not actually this length of time.
For more information, this article could help. Be aware that how this works can be rather complicated or confusing at first.
For a more simple "blueprint" that is easier to understand, try:// ...
sf::Clock clock
sf::Time frameTime{ sf::Time::Zero };
while (window.isOpen())
{
// ...
frameTime = clock.restart();
window.clear();
window.display();
}
// ...
You can see that there is only one line instead of that yellow loop and it basically stores how long it took since last time it was here (each time the clock is restarted, it returns how long it was running).
Then, you can simply multiply any motions or other values that change over time by that frame time - commonly by it in seconds:position += velocity * frameTime.asSeconds();
Thanks for your reply. I'm getting better;
sf::Time timer = sf::Time::Zero;
timer += clock.getElapsedTime(); // This happen while bool gameOver is false.
text.setString("Time: " + std::to_string(this->timer.asSeconds())); // This is what I have in my update-loop.
But how do I cut decimals off timer? I would like to decide if 1s, or 1.5s, or 1.52s (you get the picture) should be presented instead of 1.52123124s