Class: SceneManager

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.


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 14)

Members


customViewports :number

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

Type:
  • number
Since: 3.12.0
Default Value:
  • 0
Source: src/scene/SceneManager.js (Line 125)

game :Phaser.Game

The Game that this SceneManager belongs to.

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

<readonly> isBooted :boolean

Has the Scene Manager properly started?

Type:
  • boolean
Since: 3.4.0
Default Value:
  • false
Source: src/scene/SceneManager.js (Line 114)

<readonly> isProcessing :boolean

Is the Scene Manager actively processing the Scenes list?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/scene/SceneManager.js (Line 103)

keys :object

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

Type:
  • object
Since: 3.0.0
Source: src/scene/SceneManager.js (Line 45)

scenes :array

The array in which all of the scenes are kept.

Type:
  • array
Since: 3.0.0
Source: src/scene/SceneManager.js (Line 54)

Methods


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

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 Argument Default Description
key string

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

sceneConfig Phaser.Scene | Phaser.Scenes.Settings.Config | function

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.

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

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

Type
Phaser.Scene

bringToTop(key)

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.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

destroy()

Destroy the SceneManager and all of its Scene's systems.

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

dump()

Dumps debug information about each Scene to the developer console.

Since: 3.2.0
Source: src/scene/SceneManager.js (Line 1525)

getAt(index)

Retrieves a Scene by numeric index.

Parameters:
Name Type Description
index integer

The index of the Scene to retrieve.

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

The Scene.

Type
Phaser.Scene | undefined

getIndex(key)

Retrieves the numeric index of a Scene.

Parameters:
Name Type Description
key string | Phaser.Scene

The key of the Scene.

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

The index of the Scene.

Type
integer

getScene(key)

Retrieves a Scene.

Parameters:
Name Type Description
key string | Phaser.Scene

The Scene to retrieve.

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

The Scene.

Type
Phaser.Scene

isActive(key)

Determines whether a Scene is active.

Parameters:
Name Type Description
key string

The Scene to check.

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

Whether the Scene is active.

Type
boolean

isSleeping(key)

Determines whether a Scene is sleeping.

Parameters:
Name Type Description
key string

The Scene to check.

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

Whether the Scene is sleeping.

Type
boolean

isVisible(key)

Determines whether a Scene is visible.

Parameters:
Name Type Description
key string

The Scene to check.

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

Whether the Scene is visible.

Type
boolean

moveAbove(keyA, keyB)

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.

Since: 3.2.0
Source: src/scene/SceneManager.js (Line 1371)
Returns:

This SceneManager.

Type
Phaser.Scenes.SceneManager

moveBelow(keyA, keyB)

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.

Since: 3.2.0
Source: src/scene/SceneManager.js (Line 1415)
Returns:

This SceneManager.

Type
Phaser.Scenes.SceneManager

moveDown(key)

Moves a Scene down one position in the Scenes list.

Parameters:
Name Type Description
key string | Phaser.Scene

The Scene to move.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

moveUp(key)

Moves a Scene up one position in the Scenes list.

Parameters:
Name Type Description
key string | Phaser.Scene

The Scene to move.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

pause(key [, data])

Pauses the given Scene.

Parameters:
Name Type Argument Description
key string

The Scene to pause.

data object <optional>

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

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

processQueue()

Process the Scene operations queue.

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

remove(scene)

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
scene string | Phaser.Scene

The Scene to be removed.

Since: 3.2.0
Source: src/scene/SceneManager.js (Line 385)
Returns:

This SceneManager.

Type
Phaser.Scenes.SceneManager

render(renderer)

Renders the Scenes.

Parameters:
Name Type Description
renderer Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer

The renderer to use.

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

resize(width, height)

Informs the Scenes of the Game being resized.

Parameters:
Name Type Description
width number

The new width of the game.

height number

The new height of the game.

Since: 3.2.0
Source: src/scene/SceneManager.js (Line 563)

resume(key [, data])

Resumes the given Scene.

Parameters:
Name Type Argument Description
key string

The Scene to resume.

data object <optional>

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

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

run(key [, data])

Runs the given Scene, but does not change the state of this 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 Argument Description
key string

The Scene to run.

data object <optional>

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

Since: 3.10.0
Source: src/scene/SceneManager.js (Line 1026)
Returns:

This Scene Manager.

Type
Phaser.Scenes.SceneManager

sendToBack(key)

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.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

sleep(key [, data])

Puts the given Scene to sleep.

Parameters:
Name Type Argument Description
key string

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.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

start(key [, data])

Starts the given Scene.

Parameters:
Name Type Argument Description
key string

The Scene to start.

data object <optional>

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

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

stop(key)

Stops the given Scene.

Parameters:
Name Type Description
key string

The Scene to stop.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

swapPosition(keyA, keyB)

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.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

switch(from, to)

Sleeps one one Scene and starts the other.

Parameters:
Name Type Description
from string

The Scene to sleep.

to string

The Scene to start.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager

update(time, delta)

Updates the Scenes.

Parameters:
Name Type Description
time number

Time elapsed.

delta number

Delta time from the last update.

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

wake(key [, data])

Awakens the given Scene.

Parameters:
Name Type Argument Description
key string

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.

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

This SceneManager.

Type
Phaser.Scenes.SceneManager