|
constexpr | Time ()=default |
| Default constructor.
|
template<typename Rep, typename Period> |
constexpr | Time (const std::chrono::duration< Rep, Period > &duration) |
| Construct from std::chrono::duration
|
constexpr float | asSeconds () const |
| Return the time value as a number of seconds.
|
constexpr std::int32_t | asMilliseconds () const |
| Return the time value as a number of milliseconds.
|
constexpr std::int64_t | asMicroseconds () const |
| Return the time value as a number of microseconds.
|
constexpr std::chrono::microseconds | toDuration () const |
| Return the time value as a std::chrono::duration
|
template<typename Rep, typename Period> |
constexpr | operator std::chrono::duration< Rep, Period > () const |
| Implicit conversion to std::chrono::duration
|
|
(Note that these are not member symbols.)
|
constexpr Time | seconds (float amount) |
| Construct a time value from a number of seconds.
|
constexpr Time | milliseconds (std::int32_t amount) |
| Construct a time value from a number of milliseconds.
|
constexpr Time | microseconds (std::int64_t amount) |
| Construct a time value from a number of microseconds.
|
constexpr bool | operator== (Time left, Time right) |
| Overload of operator== to compare two time values.
|
constexpr bool | operator!= (Time left, Time right) |
| Overload of operator!= to compare two time values.
|
constexpr bool | operator< (Time left, Time right) |
| Overload of operator< to compare two time values.
|
constexpr bool | operator> (Time left, Time right) |
| Overload of operator> to compare two time values.
|
constexpr bool | operator<= (Time left, Time right) |
| Overload of operator<= to compare two time values.
|
constexpr bool | operator>= (Time left, Time right) |
| Overload of operator>= to compare two time values.
|
constexpr Time | operator- (Time right) |
| Overload of unary operator- to negate a time value.
|
constexpr Time | operator+ (Time left, Time right) |
| Overload of binary operator+ to add two time values.
|
constexpr Time & | operator+= (Time &left, Time right) |
| Overload of binary operator+= to add/assign two time values.
|
constexpr Time | operator- (Time left, Time right) |
| Overload of binary operator- to subtract two time values.
|
constexpr Time & | operator-= (Time &left, Time right) |
| Overload of binary operator-= to subtract/assign two time values.
|
constexpr Time | operator* (Time left, float right) |
| Overload of binary operator* to scale a time value.
|
constexpr Time | operator* (Time left, std::int64_t right) |
| Overload of binary operator* to scale a time value.
|
constexpr Time | operator* (float left, Time right) |
| Overload of binary operator* to scale a time value.
|
constexpr Time | operator* (std::int64_t left, Time right) |
| Overload of binary operator* to scale a time value.
|
constexpr Time & | operator*= (Time &left, float right) |
| Overload of binary operator*= to scale/assign a time value.
|
constexpr Time & | operator*= (Time &left, std::int64_t right) |
| Overload of binary operator*= to scale/assign a time value.
|
constexpr Time | operator/ (Time left, float right) |
| Overload of binary operator/ to scale a time value.
|
constexpr Time | operator/ (Time left, std::int64_t right) |
| Overload of binary operator/ to scale a time value.
|
constexpr Time & | operator/= (Time &left, float right) |
| Overload of binary operator/= to scale/assign a time value.
|
constexpr Time & | operator/= (Time &left, std::int64_t right) |
| Overload of binary operator/= to scale/assign a time value.
|
constexpr float | operator/ (Time left, Time right) |
| Overload of binary operator/ to compute the ratio of two time values.
|
constexpr Time | operator% (Time left, Time right) |
| Overload of binary operator% to compute remainder of a time value.
|
constexpr Time & | operator%= (Time &left, Time right) |
| Overload of binary operator%= to compute/assign remainder of a time value.
|
Represents a time value.
sf::Time encapsulates a time value in a flexible way.
It allows to define a time value either as a number of seconds, milliseconds or microseconds. It also works the other way round: you can read a time value as either a number of seconds, milliseconds or microseconds. It even interoperates with the <chrono> header. You can construct an sf::Time from a chrono::duration and read any sf::Time as a chrono::duration.
By using such a flexible interface, the API doesn't impose any fixed type or resolution for time values, and let the user choose its own favorite representation.
Time values support the usual mathematical operations: you can add or subtract two times, multiply or divide a time by a number, compare two times, etc.
Since they represent a time span and not an absolute time value, times can also be negative.
Usage example:
sf::Time t4 = std::chrono::milliseconds(250);
std::chrono::microseconds micro2 = t4.
toDuration();
constexpr float asSeconds() const
Return the time value as a number of seconds.
constexpr Time microseconds(std::int64_t amount)
Construct a time value from a number of microseconds.
constexpr Time seconds(float amount)
Construct a time value from a number of seconds.
constexpr std::int64_t asMicroseconds() const
Return the time value as a number of microseconds.
constexpr std::chrono::microseconds toDuration() const
Return the time value as a std::chrono::duration
constexpr std::int32_t asMilliseconds() const
Return the time value as a number of milliseconds.
constexpr Time milliseconds(std::int32_t amount)
Construct a time value from a number of milliseconds.
- See also
- sf::Clock
Definition at line 41 of file Time.hpp.