Class: Ticker

PIXI.ticker. Ticker

A Ticker class that runs an update loop that other objects listen to.
This class is composed around an EventEmitter object to add listeners
meant for execution on the next requested animation frame.
Animation frames are requested only when necessary,
e.g. When the ticker is started and the emitter has listeners.

new PIXI.ticker.Ticker()

Members

autoStartboolean

Whether or not this ticker should invoke the method
PIXI.ticker.Ticker#start automatically
when a listener is added.

Default Value:
  • false

deltaTimenumber

Scalar time value from last frame to this frame.
This value is capped by setting PIXI.ticker.Ticker#minFPS
and is scaled with PIXI.ticker.Ticker#speed.
Note: The cap may be exceeded by scaling.

Default Value:
  • 1

readonlyFPSnumber

The frames per second at which this ticker is running.
The default is approximately 60 in most modern browsers.
Note: This does not factor in the value of
PIXI.ticker.Ticker#speed, which is specific
to scaling PIXI.ticker.Ticker#deltaTime.

lastTimenumber

The last time PIXI.ticker.Ticker#update was invoked.
This value is also reset internally outside of invoking
update, but only when a new animation frame is requested.
If the platform supports DOMHighResTimeStamp,
this value will have a precision of 1 µs.

Default Value:
  • 0

minFPSnumber

Manages the maximum amount of milliseconds allowed to
elapse between invoking PIXI.ticker.Ticker#update.
This value is used to cap PIXI.ticker.Ticker#deltaTime,
but does not effect the measured value of PIXI.ticker.Ticker#FPS.
When setting this property it is clamped to a value between
0 and PIXI.settings.TARGET_FPMS * 1000.

Default Value:
  • 10

speednumber

Factor of current PIXI.ticker.Ticker#deltaTime.

Default Value:
  • 1
Example
// Scales ticker.deltaTime to what would be
// the equivalent of approximately 120 FPS
ticker.speed = 2;

startedboolean

Whether or not this ticker has been started.
true if PIXI.ticker.Ticker#start has been called.
false if PIXI.ticker.Ticker#stop has been called.
While false, this value may change to true in the
event of PIXI.ticker.Ticker#autoStart being true
and a listener is added.

Default Value:
  • false

Methods

Calls module:eventemitter3.EventEmitter#on internally for the
internal 'tick' event. It checks if the emitter has listeners,
and if so it requests a new animation frame at this point.

Name Type Description
fn function

The listener function to be added for updates

context function optional

The listener context

Returns:
Type Description
PIXI.ticker.Ticker This instance of a ticker

Calls module:eventemitter3.EventEmitter#once internally for the
internal 'tick' event. It checks if the emitter has listeners,
and if so it requests a new animation frame at this point.

Name Type Description
fn function

The listener function to be added for one update

context function optional

The listener context

Returns:
Type Description
PIXI.ticker.Ticker This instance of a ticker

Calls module:eventemitter3.EventEmitter#off internally for 'tick' event.
It checks if the emitter has listeners for 'tick' event.
If it does, then it cancels the animation frame.

Name Type Description
fn function optional

The listener function to be removed

context function optional

The listener context to be removed

Returns:
Type Description
PIXI.ticker.Ticker This instance of a ticker

Starts the ticker. If the ticker has listeners
a new animation frame is requested at this point.

Stops the ticker. If the ticker has requested
an animation frame it is canceled at this point.

update(currentTime)

Triggers an update. An update entails setting the
current PIXI.ticker.Ticker#elapsedMS,
the current PIXI.ticker.Ticker#deltaTime,
invoking all listeners with current deltaTime,
and then finally setting PIXI.ticker.Ticker#lastTime
with the value of currentTime that was provided.
This method will be called automatically by animation
frame callbacks if the ticker instance has been started
and listeners are added.

Name Type Default Description
currentTime number performance.now() optional

the current time of execution