Class: ScenePlugin

Phaser.Scenes. ScenePlugin

A proxy class to the Global Scene Manager.


new ScenePlugin(scene)

Parameters:
Name Type Description
scene Phaser.Scene

The Scene that this ScenePlugin belongs to.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 12)

Members


key :string

The key of the Scene this ScenePlugin belongs to.

Type:
  • string
Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 56)

manager :Phaser.Scenes.SceneManager

The Game's SceneManager.

Type:
Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 65)

scene :Phaser.Scene

The Scene that this ScenePlugin belongs to.

Type:
Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 29)

settings :Phaser.Scenes.Settings.Object

The settings of the Scene this ScenePlugin belongs to.

Type:
Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 47)

systems :Phaser.Scenes.Systems

The Scene Systems instance of the Scene that this ScenePlugin belongs to.

Type:
Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 38)

transitionProgress :number

If this Scene is currently transitioning to another, this holds
the current percentage of the transition progress, between 0 and 1.

Type:
  • number
Since: 3.5.0
Source: src/scene/ScenePlugin.js (Line 74)

Methods


add(key, sceneConfig, autoStart)

Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set.

Parameters:
Name Type Description
key string

The Scene key.

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

The config for the Scene.

autoStart boolean

Whether to start the Scene after it's added.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 437)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

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

The Scene to move.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 863)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

get(key)

Retrieve a Scene.

Parameters:
Name Type Description
key string

The Scene to retrieve.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 905)
Returns:

The Scene.

Type
Phaser.Scene

getIndex( [key])

Retrieves the numeric index of a Scene in the Scenes list.

Parameters:
Name Type Argument Description
key string | Phaser.Scene <optional>

The Scene to get the index of.

Since: 3.7.0
Source: src/scene/ScenePlugin.js (Line 920)
Returns:

The index of the Scene.

Type
integer

isActive(key)

Checks if the given Scene is active or not?

Parameters:
Name Type Description
key string

The Scene to check.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 691)
Returns:

Whether the Scene is active.

Type
boolean

isSleeping(key)

Checks if the given Scene is sleeping or not?

Parameters:
Name Type Description
key string

The Scene to check.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 674)
Returns:

Whether the Scene is sleeping.

Type
boolean

isVisible(key)

Checks if the given Scene is visible or not?

Parameters:
Name Type Description
key string

The Scene to check.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 708)
Returns:

Whether the Scene is visible.

Type
boolean

launch(key [, data])

Launch the given Scene and run it in parallel with this one.

Parameters:
Name Type Argument Description
key string

The Scene to launch.

data object <optional>

The Scene data.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 456)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

moveAbove(keyA [, keyB])

Swaps the position of two scenes in the Scenes list, so that Scene B is directly above Scene A.

This controls the order in which they are rendered and updated.

Parameters:
Name Type Argument Description
keyA string

The Scene that Scene B will be moved to be above.

keyB string <optional>

The Scene to be moved. If none is given it defaults to this Scene.

Since: 3.2.0
Source: src/scene/ScenePlugin.js (Line 750)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

moveBelow(keyA [, keyB])

Swaps the position of two scenes in the Scenes list, so that Scene B is directly below Scene A.

This controls the order in which they are rendered and updated.

Parameters:
Name Type Argument Description
keyA string

The Scene that Scene B will be moved to be below.

keyB string <optional>

The Scene to be moved. If none is given it defaults to this Scene.

Since: 3.2.0
Source: src/scene/ScenePlugin.js (Line 775)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

moveDown(key)

Moves a Scene down one position in the Scenes list.

Parameters:
Name Type Description
key string

The Scene to move.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 844)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

moveUp(key)

Moves a Scene up one position in the Scenes list.

Parameters:
Name Type Description
key string

The Scene to move.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 825)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

pause( [key] [, data])

Pause the Scene - this stops the update step from happening but it still renders.

Parameters:
Name Type Argument Description
key string <optional>

The Scene to pause.

data object <optional>

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

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 504)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

remove(key)

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 wil
queue the operation for the next update sequence.

Parameters:
Name Type Description
key string | Phaser.Scene

The Scene to be removed.

Since: 3.2.0
Source: src/scene/ScenePlugin.js (Line 800)
Returns:

This SceneManager.

Type
Phaser.Scenes.SceneManager

restart( [data])

Restarts this Scene.

Parameters:
Name Type Argument Description
data object <optional>

The Scene data.

Since: 3.4.0
Source: src/scene/ScenePlugin.js (Line 208)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

resume( [key] [, data])

Resume the Scene - starts the update loop again.

Parameters:
Name Type Argument Description
key string <optional>

The Scene to resume.

data object <optional>

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

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 524)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

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 and emitted in its ready, wake, or resume events.

Since: 3.10.0
Source: src/scene/ScenePlugin.js (Line 477)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

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

The Scene to move.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 884)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

setActive(value [, key] [, data])

Sets the active state of the given Scene.

Parameters:
Name Type Argument Description
value boolean

If true the Scene will be resumed. If false it will be paused.

key string <optional>

The Scene to set the active state of.

data object <optional>

An optional data object that will be passed to the Scene and emitted with its events.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 623)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

setVisible(value [, key])

Sets the visible state of the given Scene.

Parameters:
Name Type Argument Description
value boolean

The visible value.

key string <optional>

The Scene to set the visible state for.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 649)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

sleep( [key] [, data])

Makes the Scene sleep (no update, no render) but doesn't shutdown.

Parameters:
Name Type Argument Description
key string <optional>

The Scene to put to sleep.

data object <optional>

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

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 544)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

start( [key] [, data])

Shutdown this Scene and run the given one.

Parameters:
Name Type Argument Description
key string <optional>

The Scene to start.

data object <optional>

The Scene data.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 187)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

stop(key)

Shutdown the Scene, clearing display list, timers, etc.

Parameters:
Name Type Description
key string

The Scene to stop.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 604)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

swapPosition(keyA [, keyB])

Swaps the position of two scenes in the Scenes list.

This controls the order in which they are rendered and updated.

Parameters:
Name Type Argument Description
keyA string

The first Scene to swap.

keyB string <optional>

The second Scene to swap. If none is given it defaults to this Scene.

Since: 3.2.0
Source: src/scene/ScenePlugin.js (Line 725)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

switch(key)

Makes this Scene sleep then starts the Scene given.

Parameters:
Name Type Description
key string

The Scene to start.

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 584)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

transition(config)

This will start a transition from the current Scene to the target Scene given.

The transition will last for the duration specified in milliseconds.

You can have the target Scene moved above or below this one in the display list.

You can specify an update callback. This callback will be invoked every frame for the duration
of the transition.

This Scene can either be sent to sleep at the end of the transition, or stopped. The default is to stop.

There are also 5 transition related events: This scene will emit the event transitionto when
the transition begins, which is typically the frame after calling this method.

The target Scene will emit the event transitioninit when that Scene's init method is called.
It will then emit the event transitionstart when its create method is called.
If the Scene was sleeping and has been woken up, it will emit the event transitionwake instead of these two,
as the Scenes init and create methods are not invoked when a Scene wakes up.

When the duration of the transition has elapsed it will emit the event transitioncomplete.
These events are cleared of all listeners when the Scene shuts down, but not if it is sent to sleep.

It's important to understand that the duration of the transition begins the moment you call this method.
If the Scene you are transitioning to includes delayed processes, such as waiting for files to load, the
time still counts down even while that is happening. If the game itself pauses, or something else causes
this Scenes update loop to stop, then the transition will also pause for that duration. There are
checks in place to prevent you accidentally stopping a transitioning Scene but if you've got code to
override this understand that until the target Scene completes it might never be unlocked for input events.

Parameters:
Name Type Description
config Phaser.Scenes.ScenePlugin.SceneTransitionConfig

The transition configuration object.

Since: 3.5.0
Source: src/scene/ScenePlugin.js (Line 242)
Returns:

true is the transition was started, otherwise false.

Type
boolean

wake( [key] [, data])

Makes the Scene wake-up (starts update and render)

Parameters:
Name Type Argument Description
key string <optional>

The Scene to wake up.

data object <optional>

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

Since: 3.0.0
Source: src/scene/ScenePlugin.js (Line 564)
Returns:

This ScenePlugin object.

Type
Phaser.Scenes.ScenePlugin

Type Definitions


SceneTransitionConfig

Type:
  • object
Properties:
Name Type Argument Default Description
target string

The Scene key to transition to.

duration integer <optional>
1000

The duration, in ms, for the transition to last.

sleep boolean <optional>
false

Will the Scene responsible for the transition be sent to sleep on completion (true), or stopped? (false)

allowInput boolean <optional>
false

Will the Scenes Input system be able to process events while it is transitioning in or out?

moveAbove boolean <optional>

Move the target Scene to be above this one before the transition starts.

moveBelow boolean <optional>

Move the target Scene to be below this one before the transition starts.

onUpdate function <optional>

This callback is invoked every frame for the duration of the transition.

onUpdateScope any <optional>

The context in which the callback is invoked.

data any <optional>

An object containing any data you wish to be passed to the target Scenes init / create methods.

Source: src/scene/ScenePlugin.js (Line 228)