Using the SFML clock
The sf::Clock
class is very simple and lightweight, so it has only two methods: getElapsedTime()
and restart()
. Its sole purpose is to measure elapsed time since the last instance of the clock being restarted, or since its creation, in the most precise manner the operating system can provide. When retrieving the elapsed time using the getElapsedTime
method, it returns a type sf::Time
. The main reasoning behind that is an additional layer of abstraction to provide flexibility and avoid imposing any fixed data types. The sf::Time
class is also lightweight and provides three useful methods for conversion of elapsed time to seconds which returns a floating point value, milliseconds, which returns a 32-bit integer value and microseconds, which returns a 64-bit integer value, as represented here:
sf::Clock clock; ... sf::Time time = clock.getElapsedTime(); float seconds = time.asSeconds(); sf::Int32 milliseconds = time.asMilliseconds(); sf::Int64 microseconds = time.asMicroseconds...