Std::cout << elapsed1.asSeconds() << std::endl Sf::Time elapsed1 = clock.getElapsedTime() The time elapsed since the clock started, and restart, to restart the clock. It only has two functions: getElapsedTime, to retrieve SFML has a very simple class for measuring time: sf::Clock. Now that we've seen how to manipulate time values with SFML, let's see how to do something that almost every program needs: measuring the time elapsed. Sf::Time is just an amount of time, so it supports arithmetic operations such as addition, subtraction, comparison, etc. Similarly, a sf::Time can be converted back to either seconds, milliseconds or microseconds: Note that these three times are all equal. There is a (non-member)įunction to turn each of them into a sf::Time: It is not a date-time class which would represent theĬurrent year/month/day/hour/minute/second as a timestamp, it's just a value that represents a certain amount of time, and how to interpret it depends on the contextĪ sf::Time value can be constructed from different source units: seconds, milliseconds and microseconds. Sf::Time represents a time period (in other words, the time that elapses between two events). That manipulate time values use this class. Instead it leaves this choice to the user through a flexible class: sf::Time. Unlike many other libraries where time is a uint32 number of milliseconds, or a float number of seconds, SFML doesn't impose any specific unit or
0 Comments
Leave a Reply. |