Reset TimeKeeper to 0 time.
All ongoing timers will be cancelled, and all properties reset.
Current relative time now, of most recent animation frame or of most recent synchronized time.
Get synchronized relative now time.
Each call of now when not using manual frames will result in a
progressed time value in ms from the page load.
This can be a challenge if you want to start two animations at precisely the same time.
When syncNow is first called, the actual now time is returned. Each
subsequent call of syncNow will return the same number. syncNow is reset
on each animation frame, or after TimeKeeper.syncNowTimeout is ellapsed
(defaults to 100ms).
Current relative time.
If speed is 1 and manual frames have not been used, then this will return the time in ms after the page is loaded.
If speed is not 1, or manual frames have been or are being used, then this will return the relative time in ms taking into account pauses and frame steps from any manual frames, and any speed changes.
Set the speed of time. 1 is normal timer, >1 is faster than normal time and <1 is slower than normal time. The speed must be greater than 0.
Set manual frames.
When set, all animation frames can only be initiated with frame.
End manual frames. When ended, animation frames will again be triggered by requestAnimationFrame from the browser.
Step manual frames by a delta time in seconds.
Use like normal setTimeout in javascript.
function to be called after some time
in ms
timer description useful for debugging but not requied ('')
unique identifier that can be used to clear timer with
clearTimeout
Clear a current timer (the callback will not be called).
timer identifier return from setTimeout. If
null, no action occurs.
Queue function to be called the next time an animation frame is triggered
function that will be passed the current time as an input parameter when it is called
TimeKeeper keeps time for a figure, where time is the number of milliseconds after the page is loaded.
Time can be real time, sped up, slowed down or manually stepped.
The current time can be accessed using the
nowmethod.In it's default form,
nowis the same as the system timeperformance.now()or the animation time sent through on frames requested fromrequestAnimationFrame.However, these system times diverge from
nowwhen TimeKeeper's time speed is changed, or manual time deltas are enabled.When time speed is n times faster than real time,
nowwill report n times more passage of time from the page load than real time. So if the speed is set to 2, thennowwill report time passing twice as fast.If timeouts are needed in a figure's logic, use
figure.timeKeeper. setTimeoutandfigure.timeKeeper.clearTimeoutmethods instead of the system equivalents so the timeouts follow figure time.TimeKeeper can also be used to synchronize times (for example, for multiple animations being started where it is desired they all have precisely the same start time). See
getWhenmethod for information on how to retrieve a synchronized time