class
#include <Magnum/Timeline.h>
Timeline Timeline.
Keeps track of time delta between frames. Can be used for advancing animation playback.
Basic usage
Construct the timeline on initialization so the instance is available for the whole lifetime of the application. Call start() after the application state is fully initialized and before the first draw event is performed.
In your draw event implementation don't forget to call nextFrame() after buffer swap. You can use previousFrameDuration() to compute animation speed. To limit application framerate you can use Platform::
Example usage:
MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments, NoCreate} { … // Enable VSync or set minimal loop period for the application, if // needed/applicable ... _timeline.start(); } void MyApplication::drawEvent() { … // Distance of object traveling at speed of 15 units per second Float distance = 15.0f*_timeline.previousFrameDuration(); // Move an object, draw it ... swapBuffers(); redraw(); _timeline.nextFrame(); }
Apart from directly using the returned time values, the Timeline can also be used together with Animation::
Constructors, destructors, conversion operators
- Timeline() defaulted explicit
- Constructor.
Public functions
- void start()
- Start the timeline.
- void stop()
- Stop the timeline.
- void nextFrame()
- Advance to next frame.
- auto previousFrameTime() const -> Float
- Time at previous frame in seconds.
- auto previousFrameDuration() const -> Float
- Duration of previous frame in seconds.
- auto currentFrameTime() const -> Float new in Git master
- Current time in seconds.
- auto currentFrameDuration() const -> Float new in Git master
- Time since the last frame in seconds.
Function documentation
void Magnum:: Timeline:: stop()
Stop the timeline.
Float Magnum:: Timeline:: previousFrameTime() const
Time at previous frame in seconds.
Returns time elapsed since start() was called. If the timeline is stopped, the function returns 0.0f
.
Float Magnum:: Timeline:: previousFrameDuration() const
Duration of previous frame in seconds.
Return time measured between last two nextFrame() calls, or between start() and nextFrame(), if the previous frame was the first. If the timeline is stopped, the function returns 0.0f
. @đee currentFrameDuration()
Float Magnum:: Timeline:: currentFrameTime() const new in Git master
Current time in seconds.
Returns time elapsed since start() was called. Never smaller than previousFrameTime(). If the timeline is stopped, the function returns 0.0f
.
Float Magnum:: Timeline:: currentFrameDuration() const new in Git master
Time since the last frame in seconds.
Returns time elapsed since start() or nextFrame() was called, whichever happened last. Compared to previousFrameDuration() the returned value is different every time. If the timeline is stopped, the function returns 0.0f
.