Skip to main content
Version: Phaser v4.0.0

ScenePlugin

A Scene Level Plugin is a plugin that is installed into every Scene and belongs to that Scene for its lifetime. Unlike a Global Plugin, which exists once for the entire game, a Scene Plugin is instantiated separately for each Scene and is destroyed when its Scene is destroyed.

You would extend this class when creating your own custom plugins that need per-Scene state or need to respond to Scene lifecycle events such as start, pause, sleep, wake, shutdown, and destroy.

The plugin can map itself to a property on the Scene (e.g. this.myPlugin) and/or into the Scene Systems, making it accessible from anywhere within that Scene. Override the boot method to set up event listeners and initialize any per-Scene resources your plugin requires.

Constructor

new ScenePlugin(scene, pluginManager, pluginKey)

Parameters

nametypeoptionaldescription
scenePhaser.SceneNoA reference to the Scene that has installed this plugin.
pluginManagerPhaser.Plugins.PluginManagerNoA reference to the Plugin Manager.
pluginKeystringNoThe key under which this plugin has been installed into the Scene Systems.

Scope: static

Extends

Phaser.Plugins.BasePlugin

Source: src/plugins/ScenePlugin.js#L11
Since: 3.8.0

Inherited Members

From Phaser.Plugins.BasePlugin:


Public Members

pluginKey

pluginKey: string

Description:

The key under which this plugin was installed into the Scene Systems.

This property is only set when the plugin is instantiated and added to the Scene, not before. You can use it during the boot method.

Source: src/plugins/ScenePlugin.js#L70
Since: 3.54.0


scene

scene: Phaser.Scene

Description:

A reference to the Scene that has installed this plugin. Only set if it's a Scene Plugin, otherwise null. This property is only set when the plugin is instantiated and added to the Scene, not before. You can use it during the boot method.

Access: protected

Source: src/plugins/ScenePlugin.js#L44
Since: 3.8.0


systems

systems: Phaser.Scenes.Systems

Description:

A reference to the Scene Systems of the Scene that has installed this plugin. Only set if it's a Scene Plugin, otherwise null. This property is only set when the plugin is instantiated and added to the Scene, not before. You can use it during the boot method.

Access: protected

Source: src/plugins/ScenePlugin.js#L57
Since: 3.8.0


Inherited Methods

From Phaser.Plugins.BasePlugin:


Public Methods

boot

<instance> boot()

Description:

This method is called when the Scene boots. It is only ever called once.

By this point the plugin properties scene and systems will have already been set.

In here you can listen for Scene and set-up whatever you need for this plugin to run. Here are the Scene events you can listen to:

  • start

  • ready

  • preupdate

  • update

  • postupdate

  • resize

  • pause

  • resume

  • sleep

  • wake

  • transitioninit

  • transitionstart

  • transitioncomplete

  • transitionout

  • shutdown

  • destroy

At the very least you should offer a destroy handler for when the Scene closes down, i.e:


var eventEmitter = this.systems.events;

eventEmitter.once('destroy', this.sceneDestroy, this);

Source: src/plugins/ScenePlugin.js#L86
Since: 3.8.0


destroy

<instance> destroy()

Description:

Destroys this plugin and releases all references it holds, including the Scene, Scene Systems, and Plugin Manager. This method is called automatically when the Scene is destroyed.

If you extend this class you should override this method, clean up any resources your plugin has created, and then call BasePlugin.destroy via super.destroy() or the prototype chain.

Overrides: Phaser.Plugins.BasePlugin#destroy

Source: src/plugins/ScenePlugin.js#L125
Since: 3.8.0