Class: Clock

Phaser.Time. Clock

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


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 12)

Members


now :number

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 47)

paused :boolean

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
Since: 3.0.0
Default Value:
  • false
Source: src/time/Clock.js (Line 73)

scene :Phaser.Scene

The Scene which owns this Clock.

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

systems :Phaser.Scenes.Systems

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

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

timeScale :number

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
Since: 3.0.0
Default Value:
  • 1
Source: src/time/Clock.js (Line 61)

Methods


addEvent(config)

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

Parameters:
Name Type Description
config Phaser.Types.Time.TimerEventConfig

The configuration for the Timer Event.

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

The Timer Event which was created.

Type
Phaser.Time.TimerEvent

clearPendingEvents()

Clears and recreates the array of pending Timer Events.

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

This Clock object.

Type
Phaser.Time.Clock

delayedCall(delay, callback, args, callbackScope)

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 Description
delay number

The delay of the function call, in milliseconds.

callback function

The function to call after the delay expires.

args Array.<*>

The arguments to call the function with.

callbackScope *

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

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

The Timer Event which was created.

Type
Phaser.Time.TimerEvent

preUpdate(time, delta)

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 225)

removeAllEvents()

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

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

This Clock object.

Type
Phaser.Time.Clock

update(time, delta)

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 276)