Class: Timer

Phaser. Timer

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.

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:

Members

<static, constant> HALF :number

Type:
  • number
Source:

<static, constant> MINUTE :number

Type:
  • number
Source:

<static, constant> QUARTER :number

Type:
  • number
Source:

<static, constant> SECOND :number

Type:
  • number
Source:

autoDestroy

Properties:
Name Type Description
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:

<readonly> duration

Properties:
Name Type Description
duration number

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

Source:

events

Properties:
Name Type Description
events array.<Phaser.TimerEvent>

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

Source:

<readonly> expired

Properties:
Name Type Description
expired boolean

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

Default Value:
  • false
Source:

game

Properties:
Name Type Description
game Phaser.Game

Local reference to game.

Source:

<readonly> length

Properties:
Name Type Description
length number

The number of pending events in the queue.

Source:

<readonly> ms

Properties:
Name Type Description
ms number

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

Source:

<readonly> next

Properties:
Name Type Description
next number

The time at which the next event will occur.

Source:

<protected, readonly> nextTick

Properties:
Name Type Description
nextTick number

The time the next tick will occur.

Source:

onComplete

Properties:
Name Type Description
onComplete Phaser.Signal

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

Source:

<readonly> paused

Properties:
Name Type Description
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:

running

Properties:
Name Type Description
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:

<readonly> seconds

Properties:
Name Type Description
seconds number

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

Source:

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.

Source:
Returns:

The Phaser.TimerEvent object that was created.

Type
Phaser.TimerEvent

destroy()

Destroys this Timer. Events are not dispatched.

Source:

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.

Source:
Returns:

The Phaser.TimerEvent object that was created.

Type
Phaser.TimerEvent

order()

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

Source:

pause()

Pauses the Timer and all events in the queue.

Source:

remove(event)

Removes a pending TimerEvent from the queue.

Parameters:
Name Type Description
event Phaser.TimerEvent

The event to remove from the queue.

Source:

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

Adds a new Event to this Timer that will 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.

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.

Source:
Returns:

The Phaser.TimerEvent object that was created.

Type
Phaser.TimerEvent

resume()

Resumes the Timer and updates all pending events.

Source:

<protected> sortHandler()

Sort handler used by Phaser.Timer.order.

Source:

start()

Starts this Timer running.

Source:

stop()

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

Source:

<protected> update(time) → {boolean}

The main Timer update event, called automatically by the Game clock.

Parameters:
Name Type Description
time number

The time from the core game clock.

Source:
Returns:

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

Type
boolean
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Mon Feb 24 2014 01:12:32 GMT-0000 (GMT) using the DocStrap template.