Loading...
Searching...
No Matches

Utility class that measures the elapsed time. More...

#include <SFML/System/Clock.hpp>

Public Member Functions

Time getElapsedTime () const
 Get the elapsed time.
 
bool isRunning () const
 Check whether the clock is running.
 
void start ()
 Start the clock.
 
void stop ()
 Stop the clock.
 
Time restart ()
 Restart the clock.
 
Time reset ()
 Reset the clock.
 

Detailed Description

Utility class that measures the elapsed time.

sf::Clock is a lightweight class for measuring time.

The clock starts automatically after being constructed.

It provides the most precise time that the underlying OS can achieve (generally microseconds or nanoseconds). It also ensures monotonicity, which means that the returned time can never go backward, even if the system time is changed.

Usage example:

sf::Clock clock;
...
Time time1 = clock.getElapsedTime();
...
Time time2 = clock.restart();
...
Time time3 = clock.reset();
Utility class that measures the elapsed time.
Definition Clock.hpp:92
Time restart()
Restart the clock.
Time reset()
Reset the clock.
Time getElapsedTime() const
Get the elapsed time.
constexpr Time()=default
Default constructor.

The sf::Time value returned by the clock can then be converted to a number of seconds, milliseconds or even microseconds.

See also
sf::Time

Definition at line 91 of file Clock.hpp.

Member Function Documentation

◆ getElapsedTime()

Time sf::Clock::getElapsedTime ( ) const
nodiscard

Get the elapsed time.

This function returns the time elapsed since the last call to restart() (or the construction of the instance if restart() has not been called).

Returns
Time elapsed

◆ isRunning()

bool sf::Clock::isRunning ( ) const
nodiscard

Check whether the clock is running.

Returns
true if the clock is running, false otherwise

◆ reset()

Time sf::Clock::reset ( )

Reset the clock.

This function puts the time counter back to zero, returns the elapsed time, and leaves the clock in a paused state.

Returns
Time elapsed
See also
restart

◆ restart()

Time sf::Clock::restart ( )

Restart the clock.

This function puts the time counter back to zero, returns the elapsed time, and leaves the clock in a running state.

Returns
Time elapsed
See also
reset

◆ start()

void sf::Clock::start ( )

Start the clock.

See also
stop

◆ stop()

void sf::Clock::stop ( )

Stop the clock.

See also
start

The documentation for this class was generated from the following file: