Class: Timer

Phaser. Timer

Phaser.Timer

new Timer(game, autoDestroy)

A Timer is a way to create small re-usable or disposable objects that do nothing but wait for a specific moment in time, and then dispatch an event. You can add as many events to a Timer as you like, each with their own delays. A Timer uses milliseconds as its unit of time. There are 1000 ms in 1 second. So if you want to fire an event every quarter of a second you'd need to set the delay to 250.

Parameters:
Name Type Argument Default Description
game Phaser.Game

A reference to the currently running game.

autoDestroy boolean <optional>
true

A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events).

Source - time/Timer.js, line 17

Members

<static, constant> HALF :number

Source - time/Timer.js, line 159

<static, constant> MINUTE :number

Source - time/Timer.js, line 147

<static, constant> QUARTER :number

Source - time/Timer.js, line 165

<static, constant> SECOND :number

Source - time/Timer.js, line 153

autoDestroy :boolean

A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events).

Source - time/Timer.js, line 35

<readonly> duration :number

The duration in ms remaining until the next event will occur.

Source - time/Timer.js, line 645

<internal> elapsed :number

Elapsed time since the last frame (in ms).

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - time/Timer.js, line 48

events :array.<Phaser.TimerEvent>

An array holding all of this timers Phaser.TimerEvent objects. Use the methods add, repeat and loop to populate it.

Type:
Source - time/Timer.js, line 53

<readonly> expired :boolean

An expired Timer is one in which all of its events have been dispatched and none are pending.

Default Value:
  • false
Source - time/Timer.js, line 42

game :Phaser.Game

Local reference to game.

Source - time/Timer.js, line 24

<readonly> length :number

The number of pending events in the queue.

Source - time/Timer.js, line 667

<readonly> ms :number

The duration in milliseconds that this Timer has been running for.

Source - time/Timer.js, line 680

<readonly> next :number

The time at which the next event will occur.

Source - time/Timer.js, line 632

<internal, readonly> nextTick :number

The time the next tick will occur.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - time/Timer.js, line 65

onComplete :Phaser.Signal

This signal will be dispatched when this Timer has completed, meaning there are no more events in the queue.

Source - time/Timer.js, line 58

<readonly> paused :boolean

The paused state of the Timer. You can pause the timer by calling Timer.pause() and Timer.resume() or by the game pausing.

Default Value:
  • false
Source - time/Timer.js, line 78

running :boolean

True if the Timer is actively running. Do not switch this boolean, if you wish to pause the timer then use Timer.pause() instead.

Default Value:
  • false
Source - time/Timer.js, line 30

<readonly> seconds :number

The duration in seconds that this Timer has been running for.

Source - time/Timer.js, line 702

timeCap :number

If the difference in time between two frame updates exceeds this value, the event times are reset to avoid catch-up situations.

Source - time/Timer.js, line 71

Methods

add(delay, callback, callbackContext, arguments) → {Phaser.TimerEvent}

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. Call Timer.start() once you have added all of the Events you require for this Timer. 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.

Parameters:
Name Type Argument Description
delay number

The number of milliseconds that should elapse before the Timer will call the given callback.

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>

The values to be sent to your callback function when it is called.

Returns:

The Phaser.TimerEvent object that was created.

Source - time/Timer.js, line 208

adjustEvents()

Adjusts the time of all pending events and the nextTick by the given baseTime.

Source - time/Timer.js, line 521

clearPendingEvents()

Clears any events from the Timer which have pendingDelete set to true and then resets the private _len and _i values.

Source - time/Timer.js, line 362

destroy()

Destroys this Timer. Any pending Events are not dispatched. The onComplete callbacks won't be called.

Source - time/Timer.js, line 614

loop(delay, callback, callbackContext, arguments) → {Phaser.TimerEvent}

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' milliseconds has passed once the Timer has started running. Call Timer.start() once you have added all of the Events you require for this Timer. 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.

Parameters:
Name Type Argument Description
delay number

The number of milliseconds that should elapse before the Timer will call the given callback.

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>

The values to be sent to your callback function when it is called.

Returns:

The Phaser.TimerEvent object that was created.

Source - time/Timer.js, line 246

order()

Orders the events on this Timer so they are in tick order. This is called automatically when new events are created.

Source - time/Timer.js, line 326

pause()

Pauses the Timer and all events in the queue.

Source - time/Timer.js, line 479

remove(event)

Removes a pending TimerEvent from the queue.

Parameters:
Name Type Description
event Phaser.TimerEvent

The event to remove from the queue.

Source - time/Timer.js, line 306

removeAll()

Removes all Events from this Timer and all callbacks linked to onComplete, but leaves the Timer running. The onComplete callbacks won't be called.

Source - time/Timer.js, line 599

repeat(delay, repeatCount, callback, callbackContext, arguments) → {Phaser.TimerEvent}

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' milliseconds has passed once the Timer has started running. Call Timer.start() once you have added all of the Events you require for this Timer. 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.

Parameters:
Name Type Argument Description
delay number

The number of milliseconds that should elapse before the Timer will call the given callback.

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>

The values to be sent to your callback function when it is called.

Returns:

The Phaser.TimerEvent object that was created.

Source - time/Timer.js, line 226

resume()

Resumes the Timer and updates all pending events.

Source - time/Timer.js, line 558

<internal> sortHandler()

Sort handler used by Phaser.Timer.order.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - time/Timer.js, line 342

start(delay)

Starts this Timer running.

Parameters:
Name Type Argument Default Description
delay number <optional>
0

The number of milliseconds that should elapse before the Timer will start.

Source - time/Timer.js, line 265

stop(clearEvents)

Stops this Timer from running. Does not cause it to be destroyed if autoDestroy is set to true.

Parameters:
Name Type Argument Default Description
clearEvents boolean <optional>
true

If true all the events in Timer will be cleared, otherwise they will remain.

Source - time/Timer.js, line 288

<internal> update(time) → {boolean}

The main Timer update event, called automatically by Phaser.Time.update.

Parameters:
Name Type Description
time number

The time from the core game clock.

Returns:
boolean -

True if there are still events waiting to be dispatched, otherwise false if this Timer can be destroyed.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - time/Timer.js, line 384
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Sat Nov 15 2014 19:55:04 GMT-0000 (GMT) using the DocStrap template.