Object for keeping track of time

Remarks

This uses performance.now if it is available, otherwise it reverts to the less accurate Date.now.

See

Constructors

  • Create a new instance of Clock

    Parameters

    • Optional autoStart: boolean

      Whether to automatically start the clock when .getDelta() is called for the first time. Default true

    Returns Clock

Properties

autoStart: boolean

If set, starts the clock automatically when .getDelta() is called for the first time.

Default Value

true

elapsedTime: number

Keeps track of the total time that the clock has been running.

Default Value

0

oldTime: number

Holds the time at which the clock's .start(), .getElapsedTime() or .getDelta() methods were last called.

Default Value

0

running: boolean

Whether the clock is running or not.

Default Value

false

startTime: number

Holds the time at which the clock's .start() method was last called.

Default Value

0

Methods

  • Get the seconds passed since the time .oldTime was set and sets .oldTime to the current time.

    Returns number

    Remarks

    If .autoStart is true and the clock is not running, also starts the clock.

  • Get the seconds passed since the clock started and sets .oldTime to the current time.

    Returns number

    Remarks

    If .autoStart is true and the clock is not running, also starts the clock.

  • Starts clock.

    Returns void

    Remarks

    Also sets the .startTime and .oldTime to the current time, sets .elapsedTime to 0 and .running to true.

  • Stops clock and sets oldTime to the current time.

    Returns void