Phaser API Documentation

  Version: 
Filter

A Timer Event represents a delayed function call. It's managed by a Scene's Clock and will call its function after a set amount of time has passed. The Timer Event can optionally repeat - i.e. call its function multiple times before finishing, or loop indefinitely.

Because it's managed by a Clock, a Timer Event is based on game time, will be affected by its Clock's time scale, and will pause if its Clock pauses.

Constructor:

new TimerEvent(config)

Parameters:

name type description
config Phaser.Types.Time.TimerEventConfig

The configuration for the Timer Event, including its delay and callback.

Since: 3.0.0
Source: src/time/TimerEvent.js (Line 10)

Members

args: array
Focus
Focus

Description:

Additional arguments to be passed to the callback.

Type:
array
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 90)
Focus
Focus
callback: function
Focus
Focus

Description:

The callback that will be called when the TimerEvent occurs.

Type:
function
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 72)
Focus
Focus
callbackScope: object
Focus
Focus

Description:

The scope in which the callback will be called.

Type:
object
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 81)
Focus
Focus
<readonly> delay: number
Focus
Focus

Description:

The delay in ms at which this TimerEvent fires.

Type:
number
Default: 0
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 29)
Focus
Focus
elapsed: number
Focus
Focus

Description:

The time in milliseconds which has elapsed since the Timer Event's creation.

This value is local for the Timer Event and is relative to its Clock. As such, it's influenced by the Clock's time scale and paused state, the Timer Event's initial #startAt property, and the Timer Event's #timeScale and #paused state.

Type:
number
Default: 0
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 119)
Focus
Focus
hasDispatched: boolean
Focus
Focus

Description:

Whether the Timer Event's function has been called.

When the Timer Event fires, this property will be set to true before the callback function is invoked and will be reset immediately afterward if the Timer Event should repeat. The value of this property does not directly influence whether the Timer Event will be removed from its Clock, but can prevent it from firing.

Type:
boolean
Default: false
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 141)
Focus
Focus
<readonly> loop: boolean
Focus
Focus

Description:

True if this TimerEvent loops, otherwise false.

Type:
boolean
Default: false
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 61)
Focus
Focus
paused: boolean
Focus
Focus

Description:

Whether or not this timer is paused.

Type:
boolean
Default: false
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 131)
Focus
Focus
<readonly> repeat: number
Focus
Focus

Description:

The total number of times this TimerEvent will repeat before finishing.

Type:
number
Default: 0
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 40)
Focus
Focus
repeatCount: number
Focus
Focus

Description:

If repeating this contains the current repeat count.

Type:
number
Default: 0
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 51)
Focus
Focus
startAt: number
Focus
Focus

Description:

Start this many MS into the elapsed (useful if you want a long duration with repeat, but for the first loop to fire quickly)

Type:
number
Default: 0
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 109)
Focus
Focus
timeScale: number
Focus
Focus

Description:

Scale the time causing this TimerEvent to update.

Type:
number
Default: 1
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 99)
Focus
Focus

Methods

destroy()
Focus
Focus

Description:

Destroys all object references in the Timer Event, i.e. its callback, scope, and arguments.

Normally, this method is only called by the Clock when it shuts down. As such, it doesn't stop the Timer Event. If called manually, the Timer Event will still be updated by the Clock, but it won't do anything when it fires.

Since: 3.0.0
Source: src/time/TimerEvent.js (Line 347)
Focus
Focus
getElapsed()
Focus
Focus

Description:

Returns the local elapsed time for the current iteration of the Timer Event.

Returns:
Description:

The local elapsed time in milliseconds.

Type:
  • number
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 250)
Focus
Focus
getElapsedSeconds()
Focus
Focus

Description:

Returns the local elapsed time for the current iteration of the Timer Event in seconds.

Returns:
Description:

The local elapsed time in seconds.

Type:
  • number
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 263)
Focus
Focus
getOverallProgress()
Focus
Focus

Description:

Gets the progress of the timer overall, factoring in repeats.

Returns:
Description:

The overall progress of the Timer Event, between 0 and 1.

Type:
  • number
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 212)
Focus
Focus
getOverallRemaining()
Focus
Focus

Description:

Returns the time interval until the last iteration of the Timer Event.

Returns:
Description:

The time interval in milliseconds.

Type:
  • number
Since: 3.50.0
Source: src/time/TimerEvent.js (Line 302)
Focus
Focus
getOverallRemainingSeconds()
Focus
Focus

Description:

Returns the time interval until the last iteration of the Timer Event in seconds.

Returns:
Description:

The time interval in seconds.

Type:
  • number
Since: 3.50.0
Source: src/time/TimerEvent.js (Line 315)
Focus
Focus
getProgress()
Focus
Focus

Description:

Gets the progress of the current iteration, not factoring in repeats.

Returns:
Description:

A number between 0 and 1 representing the current progress.

Type:
  • number
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 199)
Focus
Focus
getRemaining()
Focus
Focus

Description:

Returns the time interval until the next iteration of the Timer Event.

Returns:
Description:

The time interval in milliseconds.

Type:
  • number
Since: 3.50.0
Source: src/time/TimerEvent.js (Line 276)
Focus
Focus
getRemainingSeconds()
Focus
Focus

Description:

Returns the time interval until the next iteration of the Timer Event in seconds.

Returns:
Description:

The time interval in seconds.

Type:
  • number
Since: 3.50.0
Source: src/time/TimerEvent.js (Line 289)
Focus
Focus
getRepeatCount()
Focus
Focus

Description:

Returns the number of times this Timer Event will repeat before finishing.

This should not be confused with the number of times the Timer Event will fire before finishing. A return value of 0 doesn't indicate that the Timer Event has finished running - it indicates that it will not repeat after the next time it fires.

Returns:
Description:

How many times the Timer Event will repeat.

Type:
  • number
Since: 3.0.0
Source: src/time/TimerEvent.js (Line 235)
Focus
Focus
remove([dispatchCallback])
Focus
Focus

Description:

Forces the Timer Event to immediately expire, thus scheduling its removal in the next frame.

Parameters:

name type arguments Default description
dispatchCallback boolean <optional> false

If true, the function of the Timer Event will be called before its removal.

Since: 3.0.0
Source: src/time/TimerEvent.js (Line 328)
Focus
Focus
reset(config)
Focus
Focus

Description:

Completely reinitializes the Timer Event, regardless of its current state, according to a configuration object.

Parameters:

name type description
config Phaser.Types.Time.TimerEventConfig

The new state for the Timer Event.

Returns:
Description:

This TimerEvent object.

Since: 3.0.0
Source: src/time/TimerEvent.js (Line 156)
Focus
Focus