Skip to main content
Version: Phaser v4.0.0-rc.6

Phaser.GameObjects.Components.ElapseTimer

Scope: static

Source: src/gameobjects/components/ElapseTimer.js#L7
Since: 4.0.0

Static functions

timeElapsed

timeElapsed: number

Description:

The time elapsed since timer initialization, in milliseconds.

Source: src/gameobjects/components/ElapseTimer.js#L41
Since: 4.0.0


timeElapsedResetPeriod

timeElapsedResetPeriod: number

Description:

The time after which timeElapsed will reset, in milliseconds.

By default, this is 1 hour.

If you use the timer for animations, you can set this to a period

that matches the animation durations.

This is necessary for the timer to avoid floating-point precision issues

in shaders.

A float32 can represent a few hours of milliseconds accurately,

but the precision decreases as the value increases.

Source: src/gameobjects/components/ElapseTimer.js#L50
Since: 4.0.0


timePaused

timePaused: boolean

Description:

Whether the elapse timer is paused.

Source: src/gameobjects/components/ElapseTimer.js#L68
Since: 4.0.0


Static functions

resetTimer

<instance> resetTimer([ms])

Description:

Reset the elapse timer for this game object.

Parameters:

nametypeoptionaldefaultdescription
msnumberYes0The time to reset the timer to.

Returns: Phaser.GameObjects.Components.ElapseTimer - This game object.

Source: src/gameobjects/components/ElapseTimer.js#L108
Since: 4.0.0


setTimerPaused

<instance> setTimerPaused([paused])

Description:

Pauses or resumes the elapse timer for this game object.

Parameters:

nametypeoptionaldescription
pausedbooleanYesPause state (true to pause, false to unpause). If not specified, the timer will unpause.

Returns: Phaser.GameObjects.Components.ElapseTimer - This game object.

Source: src/gameobjects/components/ElapseTimer.js#L93
Since: 4.0.0


setTimerResetPeriod

<instance> setTimerResetPeriod(period)

Description:

Set the reset period for the elapse timer for this game object.

Parameters:

nametypeoptionaldescription
periodnumberNoThe time after which timeElapsed will reset, in milliseconds.

Returns: Phaser.GameObjects.Components.ElapseTimer - This game object.

Source: src/gameobjects/components/ElapseTimer.js#L78
Since: 4.0.0


updateTimer

<instance> updateTimer(time, delta)

Description:

Update the elapse timer for this game object.

This should be called automatically by the preUpdate method.

Override this method to create more advanced time management,

or set it to a NOOP function to disable the timer update.

If you want to control animations with a tween or input system,

disabling the timer update could be useful.

Parameters:

nametypeoptionaldescription
timenumberNoThe current time in milliseconds.
deltanumberNoThe time since the last update, in milliseconds.

Returns: Phaser.GameObjects.Components.ElapseTimer - This game object.

Source: src/gameobjects/components/ElapseTimer.js#L124
Since: 4.0.0