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
-
now :number
-
The current time of the Clock, in milliseconds.
If accessed externally, this is equivalent to the
timeparameter normally passed to a Scene'supdatemethod.Type:
- number
- Since: 3.0.0
- Source: src/time/Clock.js (Line 48)
-
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 71)
-
scene :Phaser.Scene
-
The Scene which owns this Clock.
Type:
- Since: 3.0.0
- Source: src/time/Clock.js (Line 30)
-
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 39)
-
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 59)
Methods
-
addEvent(config)
-
Creates a Timer Event and adds it to the Clock at the start of the frame.
You can also pass in an existing Timer Event, which will be reset and added to this Clock.
Note that if the Timer Event 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 configPhaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig The configuration for the Timer Event, or an existing Timer Event object.
- Since: 3.0.0
- Source: src/time/Clock.js (Line 154)
Returns:
The Timer Event which was created, or passed in.
-
clearPendingEvents()
-
Clears and recreates the array of pending Timer Events.
- Since: 3.0.0
- Source: src/time/Clock.js (Line 213)
Returns:
- This Clock instance.
- 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 Argument Description delaynumber The delay of the function call, in milliseconds.
callbackfunction The function to call after the delay expires.
argsArray.<*> <optional>
The arguments to call the function with.
callbackScope* <optional>
The scope (
thisobject) to call the function with.- Since: 3.0.0
- Source: src/time/Clock.js (Line 193)
Returns:
The Timer Event which was created.
-
preUpdate(time, delta)
-
Updates the arrays of active and pending Timer Events. Called at the start of the frame.
Parameters:
Name Type Description timenumber The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
deltanumber 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 275)
-
removeAllEvents()
-
Schedules all active Timer Events for removal at the start of the frame.
- Since: 3.0.0
- Source: src/time/Clock.js (Line 260)
Returns:
- This Clock instance.
- Type
- Phaser.Time.Clock
-
removeEvent(events)
-
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 eventsPhaser.Time.TimerEvent | Array.<Phaser.Time.TimerEvent> The Timer Event, or an array of Timer Events, to remove from this Clock.
- Since: 3.50.0
- Source: src/time/Clock.js (Line 228)
Returns:
- This Clock instance.
- Type
- Phaser.Time.Clock
-
update(time, delta)
-
Updates the Clock's internal time and all of its Timer Events.
Parameters:
Name Type Description timenumber The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
deltanumber 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 326)
