- Use a sf::Clock to get the time that has passed since the last draw in seconds.
This is one way and not always the best one.
And in code this would look like:
sf::Clock clock;
float dt = 0.f;
// At the end of the game loop
dt = clock.restart().asSeconds();
This is not always the best solution since you base only upon the timespan of the last update and draw phase. If anything would spike in between there for only one frame, it would make you're framerate drop heavily only to jump back up for the next frame. This can get really annoying and totally break your smooth movments.
Other possibilities are:
- Fixed timestep (as suggested in this often linked article)
- To calculate the framerate over a longer timespan, like 1s or 0.5s.
- ... I guess there could be even more ...