A Timer is a way to create and manage timer events that wait for a specific duration and then run a callback.
Many different timer events, with individual delays, can be added to the same Timer.
All Timer delays are in milliseconds (there are 1000 ms in 1 second); so a delay value of 250 represents a quarter of a second.
Timers are based on real life time, adjusted for game pause durations.
That is, timer events are based on elapsed game time and do not take physics time or slow motion into account.
Name | Type | Argument | Default | Description |
---|---|---|---|---|
game | Phaser.Game | A reference to the currently running game. | ||
autoDestroy | boolean | <optional> | true | If true, the timer will automatically destroy itself after all the events have been dispatched (assuming no looping events). |
Number of milliseconds in half a second.
Number of milliseconds in a minute.
Number of milliseconds in a quarter of a second.
Number of milliseconds in a second.
If true, the timer will automatically destroy itself after all the events have been dispatched (assuming no looping events).
The duration in ms remaining until the next event will occur.
Elapsed time since the last frame (in ms).
An array holding all of this timers Phaser.TimerEvent objects. Use the methods add, repeat and loop to populate it.
An expired Timer is one in which all of its events have been dispatched and none are pending.
Local reference to game.
The number of pending events in the queue.
The duration in milliseconds that this Timer has been running for.
The time at which the next event will occur.
The time the next tick will occur.
This signal will be dispatched when this Timer has completed which means that there are no more events in the queue.
The signal is supplied with one argument, timer
, which is this Timer object.
The paused state of the Timer. You can pause the timer by calling Timer.pause() and Timer.resume() or by the game pausing.
True if the Timer is actively running.
Do not modify this boolean - use pause (and resume) to pause the timer.
The duration in seconds that this Timer has been running for.
If the difference in time between two frame updates exceeds this value, the event times are reset to avoid catch-up situations.
Adds a new Event to this Timer.
The event will fire after the given amount of delay
in milliseconds has passed, once the Timer has started running.
The delay is in relation to when the Timer starts, not the time it was added. If the Timer is already running the delay will be calculated based on the timers current time.
Make sure to call start after adding all of the Events you require for this Timer.
Name | Type | Argument | Description |
---|---|---|---|
delay | integer | The number of milliseconds, in game time, before the timer event occurs. | |
callback | function | The callback that will be called when the timer event occurs. | |
callbackContext | object | The context in which the callback will be called. | |
arguments | * | <repeatable> | Additional arguments that will be supplied to the callback. |
The Phaser.TimerEvent object that was created.
Adjusts the time of all pending events and the nextTick by the given baseTime.
Clears any events from the Timer which have pendingDelete set to true and then resets the private _len and _i values.
Destroys this Timer. Any pending Events are not dispatched.
The onComplete callbacks won't be called.
Adds a new looped Event to this Timer that will repeat forever or until the Timer is stopped.
The event will fire after the given amount of delay
in milliseconds has passed, once the Timer has started running.
The delay is in relation to when the Timer starts, not the time it was added. If the Timer is already running the delay will be calculated based on the timers current time.
Make sure to call start after adding all of the Events you require for this Timer.
Name | Type | Argument | Description |
---|---|---|---|
delay | integer | The number of milliseconds, in game time, before the timer event occurs. | |
callback | function | The callback that will be called when the timer event occurs. | |
callbackContext | object | The context in which the callback will be called. | |
arguments | * | <repeatable> | Additional arguments that will be supplied to the callback. |
The Phaser.TimerEvent object that was created.
Orders the events on this Timer so they are in tick order.
This is called automatically when new events are created.
Pauses the Timer and all events in the queue.
Removes a pending TimerEvent from the queue.
Name | Type | Description |
---|---|---|
event | Phaser.TimerEvent | The event to remove from the queue. |
Removes all Events from this Timer and all callbacks linked to onComplete, but leaves the Timer running.
The onComplete callbacks won't be called.
Adds a new TimerEvent that will always play through once and then repeat for the given number of iterations.
The event will fire after the given amount of delay
in milliseconds has passed, once the Timer has started running.
The delay is in relation to when the Timer starts, not the time it was added.
If the Timer is already running the delay will be calculated based on the timers current time.
Make sure to call start after adding all of the Events you require for this Timer.
Name | Type | Argument | Description |
---|---|---|---|
delay | integer | The number of milliseconds, in game time, before the timer event occurs. | |
repeatCount | number | The number of times the event will repeat once is has finished playback. A repeatCount of 1 means it will repeat itself once, playing the event twice in total. | |
callback | function | The callback that will be called when the timer event occurs. | |
callbackContext | object | The context in which the callback will be called. | |
arguments | * | <repeatable> | Additional arguments that will be supplied to the callback. |
The Phaser.TimerEvent object that was created.
Resumes the Timer and updates all pending events.
Starts this Timer running.
Name | Type | Argument | Default | Description |
---|---|---|---|---|
delay | integer | <optional> | 0 | The number of milliseconds, in game time, that should elapse before the Timer will start. |
Stops this Timer from running. Does not cause it to be destroyed if autoDestroy is set to true.
Name | Type | Argument | Default | Description |
---|---|---|---|---|
clearEvents | boolean | <optional> | true | If true all the events in Timer will be cleared, otherwise they will remain. |
The main Timer update event, called automatically by Phaser.Time.update.
Name | Type | Description |
---|---|---|
time | number | The time from the core game clock. |
True if there are still events waiting to be dispatched, otherwise false if this Timer can be destroyed.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Timer.html