Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . DOM . RequestAnimationFrame

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . DOM . RequestAnimationFrame

Abstracts away the use of RAF or setTimeOut for the core game update loop. This is invoked automatically by the Phaser.Game instance.

Constructor:

new RequestAnimationFrame()
Since: 3.0.0

Members

callback: FrameRequestCallback
Focus
Focus

Description:

The callback to be invoked each step.

Type:
FrameRequestCallback
Since: 3.0.0
Focus
Focus
isRunning: boolean
Focus
Focus

Description:

True if RequestAnimationFrame is running, otherwise false.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
isSetTimeOut: boolean
Focus
Focus

Description:

True if the step is using setTimeout instead of RAF.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
lastTime: number
Focus
Focus

Description:

The previous time the step was called.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
step: FrameRequestCallback
Focus
Focus

Description:

The RAF step function. Updates the local tick value, invokes the callback and schedules another call to requestAnimationFrame.

Type:
FrameRequestCallback
Since: 3.0.0
Focus
Focus
stepTimeout: function
Focus
Focus

Description:

The SetTimeout step function. Updates the local tick value, invokes the callback and schedules another call to setTimeout.

Type:
function
Since: 3.0.0
Focus
Focus
target: number
Focus
Focus

Description:

The target FPS rate in ms. Only used when setTimeout is used instead of RAF.

Type:
number
Default: 0
Since: 3.21.0
Focus
Focus
tick: number
Focus
Focus

Description:

The most recent timestamp. Either a DOMHighResTimeStamp under RAF or Date.now under SetTimeout.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<nullable> timeOutID: number
Focus
Focus

Description:

The setTimeout or RAF callback ID used when canceling them.

Type:
number
Default: null
Since: 3.0.0
Focus
Focus

Methods

destroy()
Focus
Focus

Description:

Stops the step from running and clears the callback reference.

Examples:
Since: 3.0.0
Focus
Focus
start(callback, forceSetTimeOut, targetFPS)
Focus
Focus

Description:

Starts the requestAnimationFrame or setTimeout process running.

Parameters:

name type description
callback FrameRequestCallback

The callback to invoke each step.

forceSetTimeOut boolean

Should it use SetTimeout, even if RAF is available?

targetFPS number

The target fps rate (in ms). Only used when setTimeout is used.

Examples:
Since: 3.0.0
Focus
Focus
stop()
Focus
Focus

Description:

Stops the requestAnimationFrame or setTimeout from running.

Examples:
Since: 3.0.0
Focus
Focus