Ticker

A game ticker that handles updating the engine every frame.

Events

NameDescriptionArguments
beforeTickTriggered at the start of every frameNone
afterTickTriggered at the end of every frameNone

Constructor

new Ticker(Game, options)

Creates a ticker that updates Game every frame.

Parameters:
NameTypeDescription
GameGame

Game ticker should be run on

optionsObject

Options object

Properties
NameTypeAttributesDefaultDescription
enabledboolean<optional>
true

If the ticker runs. To start the ticker again, use ticker.run()

pauseOnFreezeboolean<optional>
true

If the ticker should pause when the game freezes. Helps prevent jumping when user switches tabs.

freezeThresholdnumber<optional>
0.3

The threshold before the game pauses between 0 and 1. Higher values means the fps doesn't have to dip as low for the ticker to pause.

Methods

start()

Starts a stopped ticker

stop()

Stops a running ticker. This will stop physics, performance, and animation updates, but will not stop the renderer.

on(event, callback)

Binds a function to an event

Parameters:
NameTypeDescription
event"beforeTick" | "afterTick"

Name of the event

callbackfunction

Function called when event fires

off(event, callback)

Unbinds a function from an event

Parameters:
NameTypeDescription
event"beforeTick" | "afterTick"

Name of the event

callbackfunction

Function bound to event

trigger(event)

Fires an event

Parameters:
NameTypeDescription
event"beforeTick" | "afterTick"

Name of the event