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 . Scenes . SceneManager

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 . Scenes . SceneManager

The Scene Manager.

The Scene Manager is a Game level system, responsible for creating, processing and updating all of the Scenes in a Game instance.

You should not usually interact directly with the Scene Manager at all. Instead, you should use the Scene Plugin, which is available from every Scene in your game via the this.scene property.

Using methods in this Scene Manager directly will break queued operations and can cause runtime errors. Instead, go via the Scene Plugin. Every feature this Scene Manager provides is also available via the Scene Plugin.

Constructor:

new SceneManager(game, sceneConfig)

Parameters:

name type description
game Phaser.Game

The Phaser.Game instance this Scene Manager belongs to.

sceneConfig object

Scene specific configuration settings.

Since: 3.0.0
Source: src/scene/SceneManager.js (Line 17)

Members

<private> _data: object
Focus
Focus

Description:

Boot time data to merge.

Type:
object
Since: 3.4.0
Focus
Focus
<private> _pending: array
Focus
Focus

Description:

Scenes pending to be added are stored in here until the manager has time to add it.

Type:
array
Since: 3.0.0
Source: src/scene/SceneManager.js (Line 72)
Focus
Focus
<private> _queue: array
Focus
Focus

Description:

An operations queue, because we don't manipulate the scenes array during processing.

Type:
array
Since: 3.0.0
Source: src/scene/SceneManager.js (Line 92)
Focus
Focus
<private> _start: array
Focus
Focus

Description:

An array of scenes waiting to be started once the game has booted.

Type:
array
Since: 3.0.0
Source: src/scene/SceneManager.js (Line 82)
Focus
Focus
customViewports: number
Focus
Focus

Description:

Do any of the Cameras in any of the Scenes require a custom viewport? If not we can skip scissor tests.

Type:
number
Default: 0
Since: 3.12.0
Focus
Focus
game: Phaser.Game
Focus
Focus

Description:

The Game that this SceneManager belongs to.

Type:
Since: 3.0.0
Source: src/scene/SceneManager.js (Line 45)
Focus
Focus
<readonly> isBooted: boolean
Focus
Focus

Description:

Has the Scene Manager properly started?

Type:
boolean
Default: false
Since: 3.4.0
Focus
Focus
<readonly> isProcessing: boolean
Focus
Focus

Description:

Is the Scene Manager actively processing the Scenes list?

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
keys: Record.<string, Phaser.Scene>
Focus
Focus

Description:

An object that maps the keys to the scene so we can quickly get a scene from a key without iteration.

Type:
Record.<string, Phaser.Scene>
Since: 3.0.0
Source: src/scene/SceneManager.js (Line 54)
Focus
Focus
scenes: Array.<Phaser.Scene>
Focus
Focus

Description:

The array in which all of the scenes are kept.

Type:
Array.<Phaser.Scene>
Since: 3.0.0
Source: src/scene/SceneManager.js (Line 63)
Focus
Focus

Methods

add(key, sceneConfig, [autoStart], [data])
Focus
Focus

Description:

Adds a new Scene into the SceneManager. You must give each Scene a unique key by which you'll identify it.

The sceneConfig can be:

  • A Phaser.Scene object, or an object that extends it.
  • A plain JavaScript object
  • A JavaScript ES6 Class that extends Phaser.Scene
  • A JavaScript ES5 prototype based Class
  • A JavaScript function

If a function is given then a new Scene will be created by calling it.

Parameters:

name type arguments Default description
key string

A unique key used to reference the Scene, i.e. MainMenu or Level1.

sceneConfig function | Phaser.Scene | Phaser.Types.Scenes.SettingsConfig | Phaser.Types.Scenes.CreateSceneFromObjectConfig

The config for the Scene

autoStart boolean <optional> false

If true the Scene will be started immediately after being added.

data object <optional>

Optional data object. This will be set as Scene.settings.data and passed to Scene.init, and Scene.create.

Returns:
Description:

The added Scene, if it was added immediately, otherwise null.

Type:
Examples:
Since: 3.0.0
Focus
Focus
<private> bootQueue()
Focus
Focus

Description:

Internal first-time Scene boot handler.

Examples:
Since: 3.2.0
Focus
Focus
<private> bootScene(scene)
Focus
Focus

Description:

Boot the given Scene.

Parameters:

name type description
scene Phaser.Scene

The Scene to boot.

Examples:
Since: 3.0.0
Focus
Focus
bringToTop(key)
Focus
Focus

Description:

Brings a Scene to the top of the Scenes list.

This means it will render above all other Scenes.

Parameters:

name type description
key string | Phaser.Scene

The Scene to move.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
<private> create(scene)
Focus
Focus

Description:

Calls the given Scene's Phaser.Scene#create method and updates its status.

Parameters:

name type description
scene Phaser.Scene

The Scene to create.

Examples:
Since: 3.0.0
Focus
Focus
<private> createSceneFromFunction(key, scene)
Focus
Focus

Description:

Creates and initializes a Scene from a function.

Parameters:

name type description
key string

The key of the Scene.

scene function

The function to create the Scene from.

Returns:
Description:

The created Scene.

Type:
Examples:
Since: 3.0.0
Focus
Focus
<private> createSceneFromInstance(key, newScene)
Focus
Focus

Description:

Creates and initializes a Scene instance.

Parameters:

name type description
key string

The key of the Scene.

newScene Phaser.Scene

The Scene instance.

Returns:
Description:

The created Scene.

Type:
Examples:
Since: 3.0.0
Focus
Focus
<private> createSceneFromObject(key, sceneConfig)
Focus
Focus

Description:

Creates and initializes a Scene from an Object definition.

Parameters:

name type description
key string

The key of the Scene.

sceneConfig string | Phaser.Types.Scenes.SettingsConfig | Phaser.Types.Scenes.CreateSceneFromObjectConfig

The Scene config.

Returns:
Description:

The created Scene.

Type:
Examples:
Since: 3.0.0
Focus
Focus
destroy()
Focus
Focus

Description:

Destroy this Scene Manager and all of its systems.

This process cannot be reversed.

This method is called automatically when a Phaser Game instance is destroyed.

Examples:
Since: 3.0.0
Focus
Focus
dump()
Focus
Focus

Description:

Dumps debug information about each Scene to the developer console.

Examples:
Since: 3.2.0
Focus
Focus
getAt(index)
Focus
Focus

Description:

Retrieves a Scene by numeric index.

Parameters:

name type description
index number

The index of the Scene to retrieve.

Returns:
Description:

The Scene.

Type:
Examples:
Since: 3.0.0
Focus
Focus
getIndex(key)
Focus
Focus

Description:

Retrieves the numeric index of a Scene.

Parameters:

name type description
key string | Phaser.Scene

The key of the Scene.

Returns:
Description:

The index of the Scene.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
<private> getKey(key, sceneConfig)
Focus
Focus

Description:

Retrieves the key of a Scene from a Scene config.

Parameters:

name type description
key string

The key to check in the Scene config.

sceneConfig function | Phaser.Scene | Phaser.Types.Scenes.SettingsConfig

The Scene config.

Returns:
Description:

The Scene key.

Type:
  • string
Examples:
Since: 3.0.0
Focus
Focus
getScene(key)
Focus
Focus

Description:

Retrieves a Scene.

Parameters:

name type description
key string | Phaser.Scene

The Scene to retrieve.

Returns:
Description:

The Scene.

Type:
Examples:
Since: 3.0.0
Focus
Focus
getScenes([isActive], [inReverse])
Focus
Focus

Description:

Returns an array of all the current Scenes being managed by this Scene Manager.

You can filter the output by the active state of the Scene and choose to have the array returned in normal or reversed order.

Parameters:

name type arguments Default description
isActive boolean <optional> true

Only include Scene's that are currently active?

inReverse boolean <optional> false

Return the array of Scenes in reverse?

Returns:
Description:

An array containing all of the Scenes in the Scene Manager.

Type:
Examples:
Since: 3.16.0
Focus
Focus
isActive(key)
Focus
Focus

Description:

Determines whether a Scene is running.

Parameters:

name type description
key string | Phaser.Scene

The Scene to check.

Returns:
Description:

Whether the Scene is running, or null if no matching Scene was found.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
isPaused(key)
Focus
Focus

Description:

Determines whether a Scene is paused.

Parameters:

name type description
key string | Phaser.Scene

The Scene to check.

Returns:
Description:

Whether the Scene is paused, or null if no matching Scene was found.

Type:
  • boolean
Examples:
Since: 3.17.0
Focus
Focus
isSleeping(key)
Focus
Focus

Description:

Determines whether a Scene is sleeping.

Parameters:

name type description
key string | Phaser.Scene

The Scene to check.

Returns:
Description:

Whether the Scene is sleeping, or null if no matching Scene was found.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
isVisible(key)
Focus
Focus

Description:

Determines whether a Scene is visible.

Parameters:

name type description
key string | Phaser.Scene

The Scene to check.

Returns:
Description:

Whether the Scene is visible, or null if no matching Scene was found.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
<private> loadComplete(loader)
Focus
Focus

Description:

Handles load completion for a Scene's Loader.

Starts the Scene that the Loader belongs to.

Parameters:

name type description
loader Phaser.Loader.LoaderPlugin

The loader that has completed loading.

Examples:
Since: 3.0.0
Focus
Focus
moveAbove(keyA, keyB)
Focus
Focus

Description:

Moves a Scene so it is immediately above another Scene in the Scenes list.

This means it will render over the top of the other Scene.

Parameters:

name type description
keyA string | Phaser.Scene

The Scene that Scene B will be moved above.

keyB string | Phaser.Scene

The Scene to be moved.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.2.0
Focus
Focus
moveBelow(keyA, keyB)
Focus
Focus

Description:

Moves a Scene so it is immediately below another Scene in the Scenes list.

This means it will render behind the other Scene.

Parameters:

name type description
keyA string | Phaser.Scene

The Scene that Scene B will be moved above.

keyB string | Phaser.Scene

The Scene to be moved.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.2.0
Focus
Focus
moveDown(key)
Focus
Focus

Description:

Moves a Scene down one position in the Scenes list.

Parameters:

name type description
key string | Phaser.Scene

The Scene to move.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
moveUp(key)
Focus
Focus

Description:

Moves a Scene up one position in the Scenes list.

Parameters:

name type description
key string | Phaser.Scene

The Scene to move.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
pause(key, [data])
Focus
Focus

Description:

Pauses the given Scene.

Parameters:

name type arguments description
key string | Phaser.Scene

The Scene to pause.

data object <optional>

An optional data object that will be passed to the Scene and emitted by its pause event.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
<private> payloadComplete(loader)
Focus
Focus

Description:

Handle payload completion for a Scene.

Parameters:

name type description
loader Phaser.Loader.LoaderPlugin

The loader that has completed loading its Scene's payload.

Examples:
Since: 3.0.0
Focus
Focus
processQueue()
Focus
Focus

Description:

Process the Scene operations queue.

Examples:
Since: 3.0.0
Focus
Focus
<private> queueOp(op, keyA, [keyB])
Focus
Focus

Description:

Queue a Scene operation for the next update.

Parameters:

name type arguments description
op string

The operation to perform.

keyA string | Phaser.Scene

Scene A.

keyB any | string | Phaser.Scene <optional>

Scene B, or a data object.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
remove(key)
Focus
Focus

Description:

Removes a Scene from the SceneManager.

The Scene is removed from the local scenes array, it's key is cleared from the keys cache and Scene.Systems.destroy is then called on it.

If the SceneManager is processing the Scenes when this method is called it will queue the operation for the next update sequence.

Parameters:

name type description
key string

A unique key used to reference the Scene, i.e. MainMenu or Level1.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.2.0
Focus
Focus
render(renderer)
Focus
Focus

Description:

Renders the Scenes.

Parameters:

name type description
renderer Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer

The renderer to use.

Examples:
Since: 3.0.0
Focus
Focus
resume(key, [data])
Focus
Focus

Description:

Resumes the given Scene.

Parameters:

name type arguments description
key string | Phaser.Scene

The Scene to resume.

data object <optional>

An optional data object that will be passed to the Scene and emitted by its resume event.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
run(key, [data])
Focus
Focus

Description:

Runs the given Scene.

If the given Scene is paused, it will resume it. If sleeping, it will wake it. If not running at all, it will be started.

Use this if you wish to open a modal Scene by calling pause on the current Scene, then run on the modal Scene.

Parameters:

name type arguments description
key string | Phaser.Scene

The Scene to run.

data object <optional>

A data object that will be passed to the Scene on start, wake, or resume.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.10.0
Focus
Focus
sendToBack(key)
Focus
Focus

Description:

Sends a Scene to the back of the Scenes list.

This means it will render below all other Scenes.

Parameters:

name type description
key string | Phaser.Scene

The Scene to move.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
sleep(key, [data])
Focus
Focus

Description:

Puts the given Scene to sleep.

Parameters:

name type arguments description
key string | Phaser.Scene

The Scene to put to sleep.

data object <optional>

An optional data object that will be passed to the Scene and emitted by its sleep event.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
start(key, [data])
Focus
Focus

Description:

Starts the given Scene.

Parameters:

name type arguments description
key string | Phaser.Scene

The Scene to start.

data object <optional>

Optional data object to pass to Scene.Settings and Scene.init, and Scene.create.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
stop(key, [data])
Focus
Focus

Description:

Stops the given Scene.

Parameters:

name type arguments description
key string | Phaser.Scene

The Scene to stop.

data object <optional>

Optional data object to pass to Scene.shutdown.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
swapPosition(keyA, keyB)
Focus
Focus

Description:

Swaps the positions of two Scenes in the Scenes list.

Parameters:

name type description
keyA string | Phaser.Scene

The first Scene to swap.

keyB string | Phaser.Scene

The second Scene to swap.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
switch(from, to)
Focus
Focus

Description:

Sleeps one one Scene and starts the other.

Parameters:

name type description
from string | Phaser.Scene

The Scene to sleep.

to string | Phaser.Scene

The Scene to start.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus
update(time, delta)
Focus
Focus

Description:

Updates the Scenes.

Parameters:

name type description
time number

Time elapsed.

delta number

Delta time from the last update.

Examples:
Since: 3.0.0
Focus
Focus
wake(key, [data])
Focus
Focus

Description:

Awakens the given Scene.

Parameters:

name type arguments description
key string | Phaser.Scene

The Scene to wake up.

data object <optional>

An optional data object that will be passed to the Scene and emitted by its wake event.

Returns:
Description:

This Scene Manager instance.

Examples:
Since: 3.0.0
Focus
Focus