API Documentation for: 0.6.0
Show:

Ticker Class

Defined in: Ticker:35
Module: EaselJS

The Ticker provides a centralized tick or heartbeat broadcast at a set interval. Listeners can subscribe to the tick event to be notified when a set time interval has elapsed.

Note that the interval that the tick event is called is a target interval, and may be broadcast at a slower interval during times of high CPU load. The Ticker class uses a static interface (ex. Ticker.getPaused()) and should not be instantiated.

Example

 createjs.Ticker.addEventListener("tick", handleTick);
 function handleTick(event) {
     // Actions carried out each frame
 }

Methods

_getTime

() protected

Defined in _getTime:452

_handleAF

() protected

Defined in _handleAF:375

_handleTimeout

() protected

Defined in _handleTimeout:388

_setupTick

() protected

Defined in _setupTick:398

_tick

() protected

Defined in _tick:415

addEventListener

(
  • type
  • listener
)
Function | Object

Adds the specified event listener.

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

Returns:

Function | Object: Returns the listener for chaining or assignment.

addListener

(
  • o
  • pauseable
)
deprecated static

Defined in addListener:198

Deprecated: In favour of the "tick" event. Will be removed in a future version.

Adds a listener for the tick event. The listener must be either an object exposing a tick method, or a function. The listener will be called once each tick / interval. The interval is specified via the .setInterval(ms) method. The tick method or function is passed two parameters: the elapsed time between the previous tick and the current one, and a boolean indicating whether Ticker is paused.

Parameters:

  • o Object

    The object or function to add as a listener.

  • pauseable Boolean

    If false, the listener will continue to have tick called even when Ticker is paused via Ticker.pause(). Default is true.

dispatchEvent

(
  • eventObj
  • [target]
)
Boolean

Dispatches the specified event.

Parameters:

  • eventObj Object | String

    An object with a "type" property, or a string type. If a string is used, dispatchEvent will contstruct a generic event object with "type" and "params" properties.

  • [target] Object optional

    The object to use as the target property of the event object. This will default to the dispatching object.

Returns:

Boolean: Returns true if any listener returned true.

getFPS

() Number static

Defined in getFPS:296

Returns the target frame rate in frames per second (FPS). For example, with an interval of 40, getFPS() will return 25 (1000ms per second divided by 40 ms per tick = 25fps).

Returns:

Number: The current target number of frames / ticks broadcast per second.

getInterval

() Number static

Defined in getInterval:275

Returns the current target time between ticks, as set with setInterval.

Returns:

Number: The current target interval in milliseconds between tick events.

getMeasuredFPS

(
  • ticks
)
Number static

Defined in getMeasuredFPS:307

Returns the actual frames / ticks per second.

Parameters:

  • ticks Number

    Optional. The number of previous ticks over which to measure the actual frames / ticks per second. Defaults to the number of ticks per second.

Returns:

Number: The actual frames / ticks per second. Depending on performance, this may differ from the target frames per second.

getPaused

() Boolean static

Defined in getPaused:335

Returns a boolean indicating whether Ticker is currently paused, as set with setPaused.

Returns:

Boolean: Whether the Ticker is currently paused.

getTicks

(
  • pauseable
)
Number static

Defined in getTicks:360

Returns the number of ticks that have been broadcast by Ticker.

Parameters:

  • pauseable Boolean

    Indicates whether to include ticks that would have been broadcast while Ticker was paused. If true only tick events broadcast while Ticker is not paused will be returned. If false, tick events that would have been broadcast while Ticker was paused will be included in the return value. The default value is false.

Returns:

Number: of ticks that have been broadcast.

getTime

(
  • runTime
)
Number static

Defined in getTime:345

Returns the number of milliseconds that have elapsed since Ticker was initialized. For example, you could use this in a time synchronized animation to determine the exact amount of time that has elapsed.

Parameters:

  • runTime Boolean

    If true only time elapsed while Ticker was not paused will be returned. If false, the value returned will be total time elapsed since the first tick event listener was added. The default value is false.

Returns:

Number: Number of milliseconds that have elapsed since Ticker was initialized.

hasEventListener

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean: Returns true if there is at least one listener for the specified event.

init

() static

Defined in init:218

Initializes or resets the timer, clearing all associated listeners and fps measuring data, starting the tick. This is called automatically when the first listener is added.

initialize

() protected

Inherited from EventDispatcher: initialize:98

Initialization method.

removeAllEventListeners

(
  • [type]
)

Removes all listeners for the specified type, or all listeners of all types.

Parameters:

  • [type] String optional

    The string type of the event. If omitted, all listeners for all types will be removed.

removeAllListeners

() deprecated static

Defined in removeAllListeners:251

Deprecated: In favour of the "tick" event. Will be removed in a future version.

Removes all listeners.

removeEventListener

(
  • type
  • listener
)

Removes the specified event listener.

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

removeListener

(
  • o
)
deprecated static

Defined in removeListener:234

Deprecated: In favour of the "tick" event. Will be removed in a future version.

Removes the specified listener.

Parameters:

  • o Object

    The object or function to remove from listening from the tick event.

setFPS

(
  • value
)
static

Defined in setFPS:285

Sets the target frame rate in frames per second (FPS). For example, with an interval of 40, getFPS() will return 25 (1000ms per second divided by 40 ms per tick = 25fps).

Parameters:

  • value Number

    Target number of ticks broadcast per second.

setInterval

(
  • interval
)
static

Defined in setInterval:262

Sets the target time (in milliseconds) between ticks. Default is 50 (20 FPS). Note actual time between ticks may be more than requested depending on CPU load.

Parameters:

  • interval Number

    Time in milliseconds between ticks. Default value is 50.

setPaused

(
  • value
)
static

Defined in setPaused:325

While Ticker is paused, pausable listeners are not ticked. See addListener for more information.

Parameters:

  • value Boolean

    Indicates whether to pause (true) or unpause (false) Ticker.

toString

() String

Inherited from EventDispatcher: toString:191

Returns:

String: a string representation of the instance.

Properties

_inited

Boolean protected

Defined in _inited:117

_interval

Number protected

Defined in _interval:154

_lastTime

Number protected

Defined in _lastTime:161

_listeners

Array protected

Inherited from EventDispatcher but overwritten in _listeners:96

_pauseable

Array protected

Defined in _pauseable:103

_paused

Boolean protected

Defined in _paused:110

_pausedTicks

Number protected

Defined in _pausedTicks:146

Number of ticks that have passed while Ticker has been paused

_pausedTime

Number protected

Defined in _pausedTime:131

_rafActive

Boolean protected

Defined in _rafActive:182

_startTime

Number protected

Defined in _startTime:124

_ticks

Number protected

Defined in _ticks:138

Number of ticks that have passed

_tickTimes

Array protected

Defined in _tickTimes:175

_timeoutID

Number protected

Defined in _timeoutID:189

_times

Array protected

Defined in _times:168

useRAF

Boolean static

Defined in useRAF:72

Indicates whether Ticker should use requestAnimationFrame if it is supported in the browser. If false, Ticker will use setTimeout. If you use RAF, it is recommended that you set the framerate to a divisor of 60 (ex. 15, 20, 30, 60).

Default: false

Events

tick

Defined in tick:58

Available since 0.6.0

Dispatched each tick.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

  • paused Boolean

    Indicates whether the ticker is currently paused.

  • delta Number

    The time elapsed in ms since the last tick.

  • time Number

    The total time in ms since Ticker was initialized.

  • runTime Number

    The total time in ms that Ticker was not paused since it was initialized. For example, you could determine the amount of time that the Ticker has been paused since initialization with time-runTime.