Phaser API Documentation

  Version: 
Filter

The Clock is a Scene plugin which creates and updates Timer Events for its Scene.

Constructor:

new Clock(scene)

Parameters:

name type description
scene Phaser.Scene

The Scene which owns this Clock.

Since: 3.0.0
Source: src/time/Clock.js (Line 13)

Members

<private> _active: Array.<Phaser.Time.TimerEvent>
Focus
Focus

Description:

An array of all Timer Events whose delays haven't expired - these are actively updating Timer Events.

Type:
Default: []
Since: 3.0.0
Source: src/time/Clock.js (Line 83)
Focus
Focus
<private> _pendingInsertion: Array.<Phaser.Time.TimerEvent>
Focus
Focus

Description:

An array of all Timer Events which will be added to the Clock at the start of the next frame.

Type:
Default: []
Since: 3.0.0
Source: src/time/Clock.js (Line 94)
Focus
Focus
<private> _pendingRemoval: Array.<Phaser.Time.TimerEvent>
Focus
Focus

Description:

An array of all Timer Events which will be removed from the Clock at the start of the next frame.

Type:
Default: []
Since: 3.0.0
Source: src/time/Clock.js (Line 105)
Focus
Focus
now: number
Focus
Focus

Description:

The current time of the Clock, in milliseconds.

If accessed externally, this is equivalent to the time parameter normally passed to a Scene's update method.

Type:
number
Since: 3.0.0
Source: src/time/Clock.js (Line 48)
Focus
Focus
paused: boolean
Focus
Focus

Description:

Whether the Clock is paused (true) or active (false).

When paused, the Clock will not update any of its Timer Events, thus freezing time.

Type:
boolean
Default: false
Since: 3.0.0
Source: src/time/Clock.js (Line 71)
Focus
Focus
scene: Phaser.Scene
Focus
Focus

Description:

The Scene which owns this Clock.

Type:
Since: 3.0.0
Source: src/time/Clock.js (Line 30)
Focus
Focus

Description:

The Scene Systems object of the Scene which owns this Clock.

Type:
Since: 3.0.0
Source: src/time/Clock.js (Line 39)
Focus
Focus
timeScale: number
Focus
Focus

Description:

The scale of the Clock's time delta.

The time delta is the time elapsed between two consecutive frames and influences the speed of time for this Clock and anything which uses it, such as its Timer Events. Values higher than 1 increase the speed of time, while values smaller than 1 decrease it. A value of 0 freezes time and is effectively equivalent to pausing the Clock.

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

Methods

addEvent(config)
Focus
Focus

Description:

Creates a Timer Event and adds it to this Clock at the start of the next frame.

You can pass in either a TimerEventConfig object, from with a new TimerEvent will be created, or you can pass in a TimerEvent instance.

If passing an instance please make sure that this instance hasn't been used before. If it has ever entered a 'completed' state then it will no longer be suitable to run again.

Also, if the TimerEvent instance is being used by another Clock (in another Scene) it will still be updated by that Clock as well, so be careful when using this feature.

Parameters:

name type description
config Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig

The configuration for the Timer Event, or an existing Timer Event object.

Returns:
Description:

The Timer Event which was created, or passed in.

Since: 3.0.0
Source: src/time/Clock.js (Line 154)
Focus
Focus
<private> boot()
Focus
Focus

Description:

This method is called automatically, only once, when the Scene is first created. Do not invoke it directly.

Since: 3.5.1
Source: src/time/Clock.js (Line 120)
Focus
Focus
clearPendingEvents()
Focus
Focus

Description:

Clears and recreates the array of pending Timer Events.

Returns:
Description:
  • This Clock instance.
Since: 3.0.0
Source: src/time/Clock.js (Line 218)
Focus
Focus
delayedCall(delay, callback, [args], [callbackScope])
Focus
Focus

Description:

Creates a Timer Event and adds it to the Clock at the start of the frame.

This is a shortcut for #addEvent which can be shorter and is compatible with the syntax of the GreenSock Animation Platform (GSAP).

Parameters:

name type arguments description
delay number

The delay of the function call, in milliseconds.

callback function

The function to call after the delay expires.

args Array.<*> <optional>

The arguments to call the function with.

callbackScope * <optional>

The scope (this object) to call the function with.

Returns:
Description:

The Timer Event which was created.

Since: 3.0.0
Source: src/time/Clock.js (Line 198)
Focus
Focus
<private> destroy()
Focus
Focus

Description:

The Scene that owns this plugin is being destroyed. We need to shutdown and then kill off all external references.

Since: 3.0.0
Source: src/time/Clock.js (Line 433)
Focus
Focus
preUpdate(time, delta)
Focus
Focus

Description:

Updates the arrays of active and pending Timer Events. Called at the start of the frame.

Parameters:

name type description
time number

The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Since: 3.0.0
Source: src/time/Clock.js (Line 280)
Focus
Focus
removeAllEvents()
Focus
Focus

Description:

Schedules all active Timer Events for removal at the start of the frame.

Returns:
Description:
  • This Clock instance.
Since: 3.0.0
Source: src/time/Clock.js (Line 265)
Focus
Focus
removeEvent(events)
Focus
Focus

Description:

Removes the given Timer Event, or an array of Timer Events, from this Clock.

The events are removed from all internal lists (active, pending and removal), freeing the event up to be re-used.

Parameters:

name type description
events Phaser.Time.TimerEvent | Array.<Phaser.Time.TimerEvent>

The Timer Event, or an array of Timer Events, to remove from this Clock.

Returns:
Description:
  • This Clock instance.
Since: 3.50.0
Source: src/time/Clock.js (Line 233)
Focus
Focus
<private> shutdown()
Focus
Focus

Description:

The Scene that owns this plugin is shutting down. We need to kill and reset all internal properties as well as stop listening to Scene events.

Since: 3.0.0
Source: src/time/Clock.js (Line 395)
Focus
Focus
<private> start()
Focus
Focus

Description:

This method is called automatically by the Scene when it is starting up. It is responsible for creating local systems, properties and listening for Scene events. Do not invoke it directly.

Since: 3.5.0
Source: src/time/Clock.js (Line 136)
Focus
Focus
update(time, delta)
Focus
Focus

Description:

Updates the Clock's internal time and all of its Timer Events.

Parameters:

name type description
time number

The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Since: 3.0.0
Source: src/time/Clock.js (Line 331)
Focus
Focus