Skip to content

Commit 9dc7634

Browse files
committed
Added new base ScenePlugin
1 parent 4f2ef3f commit 9dc7634

2 files changed

Lines changed: 100 additions & 1 deletion

File tree

src/plugins/ScenePlugin.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser3-plugin-template/blob/master/LICENSE|MIT License}
5+
*/
6+
7+
var BasePlugin = require('./BasePlugin');
8+
var Class = require('../utils/Class');
9+
10+
/**
11+
* @classdesc
12+
* A Scene Level Plugin is installed into every Scene and belongs to that Scene.
13+
* It can listen for Scene events and respond to them.
14+
* It can map itself to a Scene property, or into the Scene Systems, or both.
15+
*
16+
* @class ScenePlugin
17+
* @memberOf Phaser.Plugins
18+
* @constructor
19+
* @since 3.8.0
20+
*
21+
* @param {Phaser.Game} game - [description]
22+
*/
23+
var ScenePlugin = new Class({
24+
25+
Extends: BasePlugin,
26+
27+
initialize:
28+
29+
function ScenePlugin (scene, pluginManager)
30+
{
31+
BasePlugin.call(this, pluginManager);
32+
33+
/**
34+
* A reference to the Scene that has installed this plugin.
35+
* This property is only set when the plugin is instantiated and added to the Scene, not before.
36+
*
37+
* @name Phaser.Plugins.ScenePlugin#scene
38+
* @type {?Phaser.Scene}
39+
* @protected
40+
* @since 3.8.0
41+
*/
42+
this.scene = scene;
43+
44+
/**
45+
* A reference to the Scene Systems of the Scene that has installed this plugin.
46+
* This property is only set when the plugin is instantiated and added to the Scene, not before.
47+
*
48+
* @name Phaser.Plugins.ScenePlugin#systems
49+
* @type {?Phaser.Scene.Systems}
50+
* @protected
51+
* @since 3.8.0
52+
*/
53+
this.systems = scene.sys;
54+
55+
scene.sys.events.once('boot', this.boot, this);
56+
},
57+
58+
/**
59+
* This method is called when the Scene boots. It is only ever called once.
60+
*
61+
* By this point the plugin properties `scene` and `systems` will have already been set.
62+
*
63+
* In here you can listen for Scene events and set-up whatever you need for this plugin to run.
64+
*
65+
* @method Phaser.Plugins.ScenePlugin#boot
66+
* @since 3.8.0
67+
*/
68+
boot: function ()
69+
{
70+
// Here are the Scene events you can listen to.
71+
// At the very least you should offer a destroy handler for when the Scene closes down:
72+
//
73+
// start
74+
// ready
75+
// preupdate
76+
// update
77+
// postupdate
78+
// resize
79+
// pause
80+
// resume
81+
// sleep
82+
// wake
83+
// transitioninit
84+
// transitionstart
85+
// transitioncomplete
86+
// transitionout
87+
// shutdown
88+
// destroy
89+
90+
// I.e.:
91+
// var eventEmitter = this.systems.events;
92+
// eventEmitter.on('start', this.sceneStart, this);
93+
// eventEmitter.once('destroy', this.sceneDestroy, this);
94+
}
95+
96+
});
97+
98+
module.exports = ScenePlugin;

src/plugins/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212

1313
BasePlugin: require('./BasePlugin'),
1414
DefaultPlugins: require('./DefaultPlugins'),
15-
PluginManager: require('./PluginManager')
15+
PluginManager: require('./PluginManager'),
16+
ScenePlugin: require('./ScenePlugin')
1617

1718
};

0 commit comments

Comments
 (0)