2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-01-16 19:49:13 +00:00
|
|
|
var Class = require('../utils/Class');
|
2018-01-23 02:12:33 +00:00
|
|
|
var CONST = require('./const');
|
2018-02-12 23:03:48 +00:00
|
|
|
var PluginManager = require('../boot/PluginManager');
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* A proxy class to the Global Scene Manager.
|
|
|
|
*
|
|
|
|
* @class ScenePlugin
|
|
|
|
* @memberOf Phaser.Scenes
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {Phaser.Scene} scene - The Scene that this ScenePlugin belongs to.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-01-18 05:20:00 +00:00
|
|
|
var ScenePlugin = new Class({
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
initialize:
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-01-18 05:20:00 +00:00
|
|
|
function ScenePlugin (scene)
|
2017-07-04 00:59:31 +00:00
|
|
|
{
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* The Scene that this ScenePlugin belongs to.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#scene
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene = scene;
|
2017-06-30 02:31:31 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* The Scene Systems instance of the Scene that this ScenePlugin belongs to.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#systems
|
|
|
|
* @type {Phaser.Scenes.Systems}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-16 02:08:22 +00:00
|
|
|
this.systems = scene.sys;
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* The settings of the Scene this ScenePlugin belongs to.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#settings
|
2018-03-21 13:41:17 +00:00
|
|
|
* @type {SettingsObject}
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
this.settings = scene.sys.settings;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* The key of the Scene this ScenePlugin belongs to.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#key
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
this.key = scene.sys.settings.key;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* The Game's SceneManager.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#manager
|
|
|
|
* @type {Phaser.Scenes.SceneManager}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-15 22:37:38 +00:00
|
|
|
this.manager = scene.sys.game.scene;
|
2018-04-13 16:12:17 +00:00
|
|
|
|
|
|
|
scene.sys.events.on('start', this.pluginStart, this);
|
2017-07-04 00:59:31 +00:00
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* This method is called automatically by the Scene when it is starting up.
|
|
|
|
* It is responsible for creating local systems, properties and listening for Scene events.
|
|
|
|
* Do not invoke it directly.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2018-04-13 16:12:17 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#pluginStart
|
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-04-13 16:12:17 +00:00
|
|
|
pluginStart: function ()
|
2018-01-16 02:08:22 +00:00
|
|
|
{
|
2018-01-18 14:00:31 +00:00
|
|
|
var eventEmitter = this.systems.events;
|
|
|
|
|
2018-04-13 16:12:17 +00:00
|
|
|
eventEmitter.once('shutdown', this.shutdown, this);
|
|
|
|
eventEmitter.once('destroy', this.destroy, this);
|
2018-01-16 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Shutdown this Scene and run the given one.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#start
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to start.
|
|
|
|
* @param {object} [data] - The Scene data.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-02-22 11:34:19 +00:00
|
|
|
start: function (key, data)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-03-08 11:27:22 +00:00
|
|
|
if (this.settings.status !== CONST.RUNNING)
|
2018-01-20 04:47:03 +00:00
|
|
|
{
|
2018-03-08 11:27:22 +00:00
|
|
|
this.manager.queueOp('stop', this.key);
|
2018-03-14 22:52:00 +00:00
|
|
|
this.manager.queueOp('start', key, data);
|
2018-03-08 11:27:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.manager.stop(this.key);
|
|
|
|
this.manager.start(key, data);
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-04-09 11:56:28 +00:00
|
|
|
/**
|
|
|
|
* Restarts this Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#restart
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @param {object} [data] - The Scene data.
|
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
|
|
|
restart: function (data)
|
|
|
|
{
|
|
|
|
var key = this.key;
|
|
|
|
|
|
|
|
if (this.settings.status !== CONST.RUNNING)
|
|
|
|
{
|
|
|
|
this.manager.queueOp('stop', key);
|
|
|
|
this.manager.queueOp('start', key, data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.manager.stop(key);
|
|
|
|
this.manager.start(key, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#add
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene key.
|
|
|
|
* @param {(Phaser.Scene|SettingsConfig|function)} sceneConfig - The config for the Scene.
|
|
|
|
* @param {boolean} autoStart - Whether to start the Scene after it's added.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
add: function (key, sceneConfig, autoStart)
|
2017-07-11 17:54:30 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.add(key, sceneConfig, autoStart);
|
2017-07-11 17:54:30 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Launch the given Scene and run it in parallel with this one.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#launch
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to launch.
|
|
|
|
* @param {object} [data] - The Scene data.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-02-22 11:34:19 +00:00
|
|
|
launch: function (key, data)
|
2017-06-30 02:31:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key && key !== this.key)
|
|
|
|
{
|
2018-01-23 02:12:33 +00:00
|
|
|
if (this.settings.status !== CONST.RUNNING)
|
|
|
|
{
|
2018-02-27 05:04:58 +00:00
|
|
|
this.manager.queueOp('start', key, data);
|
2018-01-23 02:12:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-22 11:34:19 +00:00
|
|
|
this.manager.start(key, data);
|
2018-01-23 02:12:33 +00:00
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Pause the Scene - this stops the update step from happening but it still renders.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#pause
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to pause.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2017-02-08 01:07:01 +00:00
|
|
|
pause: function (key)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.pause(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Resume the Scene - starts the update loop again.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#resume
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to resume.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2017-06-30 02:31:31 +00:00
|
|
|
resume: function (key)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.resume(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Makes the Scene sleep (no update, no render) but doesn't shutdown.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#sleep
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to put to sleep.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2017-06-30 02:31:31 +00:00
|
|
|
sleep: function (key)
|
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.sleep(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Makes the Scene wake-up (starts update and render)
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#wake
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to wake up.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2017-06-30 02:31:31 +00:00
|
|
|
wake: function (key)
|
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.wake(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Makes this Scene sleep then starts the Scene given.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#switch
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to start.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
switch: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key !== this.key)
|
|
|
|
{
|
2018-01-23 02:12:33 +00:00
|
|
|
if (this.settings.status !== CONST.RUNNING)
|
|
|
|
{
|
|
|
|
this.manager.queueOp('switch', this.key, key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.manager.switch(this.key, key);
|
|
|
|
}
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Shutdown the Scene, clearing display list, timers, etc.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#stop
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to stop.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2017-06-30 02:31:31 +00:00
|
|
|
stop: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2017-06-30 02:31:31 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.stop(key);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Sets the active state of the given Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#setActive
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {boolean} value - The Scene to set the active state for.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
setActive: function (value)
|
|
|
|
{
|
|
|
|
this.settings.active = value;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Sets the visible state of the given Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#setVisible
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {boolean} value - The Scene to set the visible state for.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2017-06-30 02:31:31 +00:00
|
|
|
setVisible: function (value)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2017-06-30 02:31:31 +00:00
|
|
|
this.settings.visible = value;
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given Scene is sleeping or not?
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#isSleeping
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to check.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @return {boolean} Whether the Scene is sleeping.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
isSleeping: function (key)
|
2017-07-11 15:48:25 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.isSleeping(key);
|
2017-07-11 15:48:25 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given Scene is active or not?
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#isActive
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to check.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @return {boolean} Whether the Scene is active.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
isActive: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.isActive(key);
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given Scene is visible or not?
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#isVisible
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to check.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @return {boolean} Whether the Scene is visible.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
isVisible: function (key)
|
2017-06-30 02:31:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.isVisible(key);
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-03-02 17:47:01 +00:00
|
|
|
* Swaps the position of two scenes in the Scenes list.
|
2018-04-02 17:29:23 +00:00
|
|
|
*
|
2018-03-02 17:47:01 +00:00
|
|
|
* This controls the order in which they are rendered and updated.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#swapPosition
|
2018-03-02 17:47:01 +00:00
|
|
|
* @since 3.2.0
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2018-03-02 17:47:01 +00:00
|
|
|
* @param {string} keyA - The first Scene to swap.
|
|
|
|
* @param {string} [keyB] - The second Scene to swap. If none is given it defaults to this Scene.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-03-02 17:47:01 +00:00
|
|
|
swapPosition: function (keyA, keyB)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-03-02 17:47:01 +00:00
|
|
|
if (keyB === undefined) { keyB = this.key; }
|
|
|
|
|
|
|
|
if (keyA !== keyB)
|
2018-01-20 04:47:03 +00:00
|
|
|
{
|
2018-03-02 17:47:01 +00:00
|
|
|
this.manager.swapPosition(keyA, keyB);
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:25:44 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Swaps the position of two scenes in the Scenes list, so that Scene B is directly above Scene A.
|
2018-04-02 17:29:23 +00:00
|
|
|
*
|
2018-03-02 18:25:44 +00:00
|
|
|
* This controls the order in which they are rendered and updated.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#moveAbove
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
|
|
|
* @param {string} keyA - The Scene that Scene B will be moved to be above.
|
|
|
|
* @param {string} [keyB] - The Scene to be moved. If none is given it defaults to this Scene.
|
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
|
|
|
moveAbove: function (keyA, keyB)
|
|
|
|
{
|
|
|
|
if (keyB === undefined) { keyB = this.key; }
|
|
|
|
|
|
|
|
if (keyA !== keyB)
|
|
|
|
{
|
|
|
|
this.manager.moveAbove(keyA, keyB);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Swaps the position of two scenes in the Scenes list, so that Scene B is directly below Scene A.
|
2018-04-02 17:29:23 +00:00
|
|
|
*
|
2018-03-02 18:25:44 +00:00
|
|
|
* This controls the order in which they are rendered and updated.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#moveBelow
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
|
|
|
* @param {string} keyA - The Scene that Scene B will be moved to be below.
|
|
|
|
* @param {string} [keyB] - The Scene to be moved. If none is given it defaults to this Scene.
|
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
|
|
|
moveBelow: function (keyA, keyB)
|
|
|
|
{
|
|
|
|
if (keyB === undefined) { keyB = this.key; }
|
|
|
|
|
|
|
|
if (keyA !== keyB)
|
|
|
|
{
|
|
|
|
this.manager.moveBelow(keyA, keyB);
|
|
|
|
}
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
return this;
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-03-02 03:50:55 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#remove
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to be removed.
|
2018-03-02 03:50:55 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.SceneManager} This SceneManager.
|
|
|
|
*/
|
|
|
|
remove: function (key)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.remove(key);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* Moves a Scene up one position in the Scenes list.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#moveUp
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to move.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
moveUp: function (key)
|
2017-06-30 02:31:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.moveUp(key);
|
|
|
|
|
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* Moves a Scene down one position in the Scenes list.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#moveDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to move.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
moveDown: function (key)
|
2017-07-05 02:47:32 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.moveDown(key);
|
|
|
|
|
|
|
|
return this;
|
2017-07-05 02:47:32 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* Brings a Scene to the top of the Scenes list.
|
|
|
|
*
|
|
|
|
* This means it will render above all other Scenes.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#bringToTop
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to move.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
bringToTop: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
this.manager.bringToTop(key);
|
|
|
|
|
|
|
|
return this;
|
2017-02-08 01:07:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* Sends a Scene to the back of the Scenes list.
|
|
|
|
*
|
|
|
|
* This means it will render below all other Scenes.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#sendToBack
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to move.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
|
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
sendToBack: function (key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-01-20 04:47:03 +00:00
|
|
|
this.manager.sendToBack(key);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-02 17:29:23 +00:00
|
|
|
* Retrieve a Scene.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#get
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {string} key - The Scene to retrieve.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2018-04-02 17:29:23 +00:00
|
|
|
* @return {Phaser.Scene} The Scene.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-01-20 04:47:03 +00:00
|
|
|
get: function (key)
|
|
|
|
{
|
|
|
|
return this.manager.getScene(key);
|
2018-01-16 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* The Scene that owns this plugin is shutting down.
|
|
|
|
* We need to kill and reset all internal properties as well as stop listening to Scene events.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#shutdown
|
2018-04-13 16:12:17 +00:00
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-04-13 17:09:16 +00:00
|
|
|
shutdown: function ()
|
2018-01-16 02:08:22 +00:00
|
|
|
{
|
2018-04-13 16:12:17 +00:00
|
|
|
var eventEmitter = this.systems.events;
|
|
|
|
|
|
|
|
eventEmitter.off('shutdown', this.shutdown, this);
|
2018-01-16 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* The Scene that owns this plugin is being destroyed.
|
|
|
|
* We need to shutdown and then kill off all external references.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#destroy
|
2018-04-13 16:12:17 +00:00
|
|
|
* @private
|
2018-02-12 16:18:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-16 02:08:22 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-04-13 16:12:17 +00:00
|
|
|
this.shutdown();
|
|
|
|
|
|
|
|
this.scene.sys.events.off('start', this.start, this);
|
|
|
|
|
|
|
|
this.scene = null;
|
|
|
|
this.systems = null;
|
|
|
|
this.settings = null;
|
|
|
|
this.manager = null;
|
2017-02-08 01:07:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
});
|
2017-06-30 02:31:31 +00:00
|
|
|
|
2018-01-18 05:20:00 +00:00
|
|
|
PluginManager.register('ScenePlugin', ScenePlugin, 'scenePlugin');
|
2018-01-16 02:08:22 +00:00
|
|
|
|
2018-01-18 05:20:00 +00:00
|
|
|
module.exports = ScenePlugin;
|