phaser/src/plugins/ScenePlugin.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-05-11 15:01:23 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-05-11 15:01:23 +00:00
* @license {@link https://github.com/photonstorm/phaser3-plugin-template/blob/master/LICENSE|MIT License}
*/
var BasePlugin = require('./BasePlugin');
var Class = require('../utils/Class');
2019-01-18 13:41:43 +00:00
var SceneEvents = require('../scene/events');
2018-05-11 15:01:23 +00:00
/**
* @classdesc
* A Scene Level Plugin is installed into every Scene and belongs to that Scene.
* It can listen for Scene events and respond to them.
* It can map itself to a Scene property, or into the Scene Systems, or both.
*
* @class ScenePlugin
2018-10-10 09:49:13 +00:00
* @memberof Phaser.Plugins
2018-05-18 16:37:20 +00:00
* @extends Phaser.Plugins.BasePlugin
2018-05-11 15:01:23 +00:00
* @constructor
* @since 3.8.0
*
2018-05-25 16:20:50 +00:00
* @param {Phaser.Scene} scene - A reference to the Scene that has installed this plugin.
* @param {Phaser.Plugins.PluginManager} pluginManager - A reference to the Plugin Manager.
2018-05-11 15:01:23 +00:00
*/
var ScenePlugin = new Class({
Extends: BasePlugin,
initialize:
function ScenePlugin (scene, pluginManager)
{
BasePlugin.call(this, pluginManager);
this.scene = scene;
this.systems = scene.sys;
2019-01-18 13:41:43 +00:00
scene.sys.events.once(SceneEvents.BOOT, this.boot, this);
2018-05-11 15:01:23 +00:00
},
/**
* 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 events and set-up whatever you need for this plugin to run.
2018-05-11 15:24:10 +00:00
* 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:
*
* ```javascript
* var eventEmitter = this.systems.events;
* eventEmitter.once('destroy', this.sceneDestroy, this);
* ```
2018-05-11 15:01:23 +00:00
*
* @method Phaser.Plugins.ScenePlugin#boot
* @since 3.8.0
*/
boot: function ()
{
}
});
module.exports = ScenePlugin;