Skip to main content
Version: Phaser v4.0.0

RequestAnimationFrame

Abstracts away the use of requestAnimationFrame or setTimeout for the core game update loop, providing a unified interface regardless of which mechanism is in use.

When requestAnimationFrame is available and not overridden, it is used to drive the game loop, which ties updates to the display refresh rate and pauses automatically when the tab is hidden. If forceSetTimeOut is enabled in the Game Config, setTimeout is used instead, which runs at a fixed interval regardless of visibility or display sync.

This class is instantiated and managed automatically by the Phaser.Game instance.

Scope: static

Source: src/dom/RequestAnimationFrame.js#L10
Since: 3.0.0

Public Members​

callback​

callback: FrameRequestCallback​

Description:

The callback to be invoked each step.

Source: src/dom/RequestAnimationFrame.js#L43
Since: 3.0.0


delay​

delay: number​

Description:

The delay, in milliseconds, between each step when using setTimeout.

Source: src/dom/RequestAnimationFrame.js#L72
Since: 3.60.0


isRunning​

isRunning: boolean​

Description:

True if RequestAnimationFrame is running, otherwise false.

Source: src/dom/RequestAnimationFrame.js#L33
Since: 3.0.0


isSetTimeOut​

isSetTimeOut: boolean​

Description:

True if the step is using setTimeout instead of RAF.

Source: src/dom/RequestAnimationFrame.js#L52
Since: 3.0.0


step​

step: FrameRequestCallback​

Description:

The RAF step function.

Invokes the callback and schedules another call to requestAnimationFrame.

Parameters:

nametypeoptionaldescription
timenumberNoThe timestamp passed in from RequestAnimationFrame.

Source: src/dom/RequestAnimationFrame.js#L84
Since: 3.0.0


stepTimeout​

stepTimeout: function​

Description:

The SetTimeout step function.

Invokes the callback and schedules another call to setTimeout.

Source: src/dom/RequestAnimationFrame.js#L105
Since: 3.0.0


timeOutID​

timeOutID: number​

Description:

The setTimeout or RAF callback ID used when canceling them.

Source: src/dom/RequestAnimationFrame.js#L62
Since: 3.0.0


Public Methods​

destroy​

<instance> destroy()​

Description:

Stops the step from running and clears the callback reference.

Source: src/dom/RequestAnimationFrame.js#L174
Since: 3.0.0


start​

<instance> start(callback, forceSetTimeOut, delay)​

Description:

Starts the requestAnimationFrame or setTimeout process running.

Parameters:

nametypeoptionaldescription
callbackFrameRequestCallbackNoThe callback to invoke each step.
forceSetTimeOutbooleanNoShould it use SetTimeout, even if RAF is available?
delaynumberNoThe delay, in milliseconds, between each step when using setTimeout.

Source: src/dom/RequestAnimationFrame.js#L126
Since: 3.0.0


stop​

<instance> stop()​

Description:

Stops the requestAnimationFrame or setTimeout from running.

Source: src/dom/RequestAnimationFrame.js#L154
Since: 3.0.0