figureone
    Preparing search index...

    Class default

    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 now method.

    In it's default form, now is the same as the system time performance.now() or the animation time sent through on frames requested from requestAnimationFrame .

    However, these system times diverge from now when TimeKeeper's time speed is changed, or manual time deltas are enabled.

    When time speed is n times faster than real time, now will report n times more passage of time from the page load than real time. So if the speed is set to 2, then now will report time passing twice as fast.

    If timeouts are needed in a figure's logic, use figure.timeKeeper. setTimeout and figure.timeKeeper.clearTimeout methods 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 getWhen method for information on how to retrieve a synchronized time

    Index

    Methods

    • Reset TimeKeeper to 0 time.

      All ongoing timers will be cancelled, and all properties reset.

      Returns void

    • 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).

      Returns number

    • 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.

      Returns number

    • 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.

      Parameters

      • speedFactor: number = 1

      Returns void

    • Set manual frames. When set, all animation frames can only be initiated with frame.

      Returns void

    • End manual frames. When ended, animation frames will again be triggered by requestAnimationFrame from the browser.

      Returns void

    • Step manual frames by a delta time in seconds.

      Parameters

      • timeStepInSeconds: number

      Returns void

    • Use like normal setTimeout in javascript.

      Parameters

      • callback: () => void

        function to be called after some time

      • time: number

        in ms

      • description: string = ''

        timer description useful for debugging but not requied ('')

      • stateTimer: boolean = false

      Returns number

      unique identifier that can be used to clear timer with clearTimeout

    • Clear a current timer (the callback will not be called).

      Parameters

      • id: number | null

        timer identifier return from setTimeout. If null, no action occurs.

      Returns void

    • Queue function to be called the next time an animation frame is triggered

      Parameters

      • func: (time: number | null) => void

        function that will be passed the current time as an input parameter when it is called

      Returns void