2018-02-12 16:01:20 +00:00
|
|
|
/**
|
2024-02-19 17:12:18 +00:00
|
|
|
* @author Richard Davey <rich@phaser.io>
|
|
|
|
* @copyright 2013-2024 Phaser Studio Inc.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
var Clamp = require('../math/Clamp');
|
2018-01-16 19:49:13 +00:00
|
|
|
var Class = require('../utils/Class');
|
2019-01-18 12:19:41 +00:00
|
|
|
var Events = require('./events');
|
2018-04-14 03:23:57 +00:00
|
|
|
var GetFastValue = require('../utils/object/GetFastValue');
|
2018-05-15 11:51:50 +00:00
|
|
|
var PluginCache = require('../plugins/PluginCache');
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2021-02-16 13:21:31 +00:00
|
|
|
* The Scene Plugin is the main interface to the Scene Manager and allows you to control
|
|
|
|
* any Scene running in your game. You should always use this plugin. By default, it is
|
|
|
|
* mapped to the Scene property `this.scene`. Meaning, from within a Scene, you can call
|
|
|
|
* methods such as `this.scene.start()`.
|
|
|
|
*
|
|
|
|
* Note that nearly all methods in this class are run on a queue-basis and not
|
|
|
|
* immediately. For example, calling `this.scene.launch('SceneB')` will try to
|
|
|
|
* launch SceneB when the Scene Manager next updates, which is at the start of the game
|
|
|
|
* step. All operations are queued and run in the order in which they are invoked here.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @class ScenePlugin
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Scenes
|
2018-02-12 16:18:34 +00:00
|
|
|
* @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
|
2019-05-09 11:37:37 +00:00
|
|
|
* @type {Phaser.Types.Scenes.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
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
/**
|
|
|
|
* If this Scene is currently transitioning to another, this holds
|
|
|
|
* the current percentage of the transition progress, between 0 and 1.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#transitionProgress
|
2018-06-26 22:19:14 +00:00
|
|
|
* @type {number}
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-14 03:23:57 +00:00
|
|
|
*/
|
|
|
|
this.transitionProgress = 0;
|
|
|
|
|
2018-04-13 17:59:00 +00:00
|
|
|
/**
|
|
|
|
* Transition elapsed timer.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#_elapsed
|
2020-11-23 10:22:13 +00:00
|
|
|
* @type {number}
|
2018-04-13 17:59:00 +00:00
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 17:59:00 +00:00
|
|
|
*/
|
|
|
|
this._elapsed = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transition elapsed timer.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#_target
|
2022-10-09 17:11:00 +00:00
|
|
|
* @type {?Phaser.Scene}
|
2018-04-13 17:59:00 +00:00
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 17:59:00 +00:00
|
|
|
*/
|
2018-04-13 19:12:29 +00:00
|
|
|
this._target = null;
|
2018-04-13 17:59:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transition duration.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#_duration
|
2020-11-23 10:22:13 +00:00
|
|
|
* @type {number}
|
2018-04-13 17:59:00 +00:00
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 17:59:00 +00:00
|
|
|
*/
|
|
|
|
this._duration = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transition callback.
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#_onUpdate
|
|
|
|
* @type {function}
|
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 17:59:00 +00:00
|
|
|
*/
|
|
|
|
this._onUpdate;
|
|
|
|
|
|
|
|
/**
|
2018-04-14 11:35:28 +00:00
|
|
|
* Transition callback scope.
|
2018-04-13 17:59:00 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#_onUpdateScope
|
|
|
|
* @type {object}
|
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 17:59:00 +00:00
|
|
|
*/
|
|
|
|
this._onUpdateScope;
|
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
/**
|
|
|
|
* Will this Scene sleep (true) after the transition, or stop (false)
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#_willSleep
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-14 03:23:57 +00:00
|
|
|
*/
|
|
|
|
this._willSleep = false;
|
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
/**
|
|
|
|
* Will this Scene be removed from the Scene Manager after the transition completes?
|
|
|
|
*
|
|
|
|
* @name Phaser.Scenes.ScenePlugin#_willRemove
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
* @since 3.5.0
|
|
|
|
*/
|
|
|
|
this._willRemove = false;
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
scene.sys.events.once(Events.BOOT, this.boot, this);
|
|
|
|
scene.sys.events.on(Events.START, this.pluginStart, this);
|
2017-07-04 00:59:31 +00:00
|
|
|
},
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2018-04-17 11:25:45 +00:00
|
|
|
/**
|
|
|
|
* This method is called automatically, only once, when the Scene is first created.
|
|
|
|
* Do not invoke it directly.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#boot
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
boot: function ()
|
|
|
|
{
|
2019-01-18 13:41:43 +00:00
|
|
|
this.systems.events.once(Events.DESTROY, this.destroy, this);
|
2018-04-17 11:25:45 +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-04-17 11:25:45 +00:00
|
|
|
* @since 3.5.0
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-04-13 16:12:17 +00:00
|
|
|
pluginStart: function ()
|
2018-01-16 02:08:22 +00:00
|
|
|
{
|
2018-04-14 03:23:57 +00:00
|
|
|
this._target = null;
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
this.systems.events.once(Events.SHUTDOWN, this.shutdown, 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.
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-02-12 16:18:34 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#start
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to start.
|
2021-10-29 16:53:57 +00:00
|
|
|
* @param {object} [data] - The Scene data. If no value is given it will not overwrite any previous data that may exist.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
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-06-26 15:35:45 +00:00
|
|
|
this.manager.queueOp('stop', this.key);
|
|
|
|
this.manager.queueOp('start', key, data);
|
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.
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-04-09 11:56:28 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#restart
|
|
|
|
* @since 3.4.0
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2021-10-29 16:53:57 +00:00
|
|
|
* @param {object} [data] - The Scene data. If no value is given it will not overwrite any previous data that may exist.
|
2018-04-09 11:56:28 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-04-09 11:56:28 +00:00
|
|
|
*/
|
|
|
|
restart: function (data)
|
|
|
|
{
|
|
|
|
var key = this.key;
|
|
|
|
|
2018-06-26 15:35:45 +00:00
|
|
|
this.manager.queueOp('stop', key);
|
|
|
|
this.manager.queueOp('start', key, data);
|
2018-04-09 11:56:28 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
/**
|
|
|
|
* This will start a transition from the current Scene to the target Scene given.
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2022-05-06 15:38:19 +00:00
|
|
|
* The target Scene cannot be the same as the current Scene.
|
|
|
|
*
|
2018-04-14 03:23:57 +00:00
|
|
|
* The transition will last for the duration specified in milliseconds.
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2018-04-14 03:23:57 +00:00
|
|
|
* You can have the target Scene moved above or below this one in the display list.
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2018-04-14 03:23:57 +00:00
|
|
|
* You can specify an update callback. This callback will be invoked _every frame_ for the duration
|
|
|
|
* of the transition.
|
2018-04-13 17:59:00 +00:00
|
|
|
*
|
2018-04-14 03:23:57 +00:00
|
|
|
* This Scene can either be sent to sleep at the end of the transition, or stopped. The default is to stop.
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2019-01-18 12:19:41 +00:00
|
|
|
* There are also 5 transition related events: This scene will emit the event `transitionout` when
|
2018-04-15 22:14:56 +00:00
|
|
|
* the transition begins, which is typically the frame after calling this method.
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2018-04-15 22:14:56 +00:00
|
|
|
* 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,
|
2018-10-03 21:07:41 +00:00
|
|
|
* as the Scenes `init` and `create` methods are not invoked when a Scene wakes up.
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2018-04-15 22:14:56 +00:00
|
|
|
* When the duration of the transition has elapsed it will emit the event `transitioncomplete`.
|
2018-10-03 21:07:41 +00:00
|
|
|
* These events are cleared of all listeners when the Scene shuts down, but not if it is sent to sleep.
|
2018-04-15 22:14:56 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2018-04-13 17:59:00 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#transition
|
2019-01-18 12:19:41 +00:00
|
|
|
* @fires Phaser.Scenes.Events#TRANSITION_OUT
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 17:59:00 +00:00
|
|
|
*
|
2019-05-09 11:37:37 +00:00
|
|
|
* @param {Phaser.Types.Scenes.SceneTransitionConfig} config - The transition configuration object.
|
2018-04-13 17:59:00 +00:00
|
|
|
*
|
2018-04-14 03:23:57 +00:00
|
|
|
* @return {boolean} `true` is the transition was started, otherwise `false`.
|
2018-04-13 17:59:00 +00:00
|
|
|
*/
|
2018-04-14 03:23:57 +00:00
|
|
|
transition: function (config)
|
2018-04-13 17:59:00 +00:00
|
|
|
{
|
2018-04-14 03:23:57 +00:00
|
|
|
if (config === undefined) { config = {}; }
|
|
|
|
|
|
|
|
var key = GetFastValue(config, 'target', false);
|
|
|
|
|
|
|
|
var target = this.manager.getScene(key);
|
|
|
|
|
|
|
|
if (!key || !this.checkValidTransition(target))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var duration = GetFastValue(config, 'duration', 1000);
|
|
|
|
|
|
|
|
this._elapsed = 0;
|
|
|
|
this._target = target;
|
|
|
|
this._duration = duration;
|
|
|
|
this._willSleep = GetFastValue(config, 'sleep', false);
|
2018-04-15 22:14:56 +00:00
|
|
|
this._willRemove = GetFastValue(config, 'remove', false);
|
2018-04-13 17:59:00 +00:00
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
var callback = GetFastValue(config, 'onUpdate', null);
|
2018-04-13 17:59:00 +00:00
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
if (callback)
|
2018-04-13 17:59:00 +00:00
|
|
|
{
|
|
|
|
this._onUpdate = callback;
|
2018-04-14 03:23:57 +00:00
|
|
|
this._onUpdateScope = GetFastValue(config, 'onUpdateScope', this.scene);
|
|
|
|
}
|
2018-04-13 17:59:00 +00:00
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
var allowInput = GetFastValue(config, 'allowInput', false);
|
2018-04-13 17:59:00 +00:00
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
this.settings.transitionAllowInput = allowInput;
|
2018-04-13 17:59:00 +00:00
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
var targetSettings = target.sys.settings;
|
2018-04-13 17:59:00 +00:00
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
targetSettings.isTransition = true;
|
|
|
|
targetSettings.transitionFrom = this.scene;
|
|
|
|
targetSettings.transitionDuration = duration;
|
|
|
|
targetSettings.transitionAllowInput = allowInput;
|
|
|
|
|
|
|
|
if (GetFastValue(config, 'moveAbove', false))
|
|
|
|
{
|
|
|
|
this.manager.moveAbove(this.key, key);
|
|
|
|
}
|
|
|
|
else if (GetFastValue(config, 'moveBelow', false))
|
|
|
|
{
|
|
|
|
this.manager.moveBelow(this.key, key);
|
2018-04-13 17:59:00 +00:00
|
|
|
}
|
|
|
|
|
2018-04-14 03:28:39 +00:00
|
|
|
if (target.sys.isSleeping())
|
|
|
|
{
|
2020-04-08 18:20:01 +00:00
|
|
|
target.sys.wake(GetFastValue(config, 'data'));
|
2018-04-14 03:28:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-18 12:29:22 +00:00
|
|
|
this.manager.start(key, GetFastValue(config, 'data'));
|
2018-04-14 03:28:39 +00:00
|
|
|
}
|
2018-04-14 03:23:57 +00:00
|
|
|
|
2022-02-15 02:10:33 +00:00
|
|
|
var onStartCallback = GetFastValue(config, 'onStart', null);
|
|
|
|
|
|
|
|
var onStartScope = GetFastValue(config, 'onStartScope', this.scene);
|
|
|
|
|
|
|
|
if (onStartCallback)
|
|
|
|
{
|
|
|
|
onStartCallback.call(onStartScope, this.scene, target, duration);
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:19:41 +00:00
|
|
|
this.systems.events.emit(Events.TRANSITION_OUT, target, duration);
|
2018-04-14 03:23:57 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if this Scene can transition to the target Scene or not.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#checkValidTransition
|
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-14 03:23:57 +00:00
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} target - The Scene to test against.
|
|
|
|
*
|
|
|
|
* @return {boolean} `true` if this Scene can transition, otherwise `false`.
|
|
|
|
*/
|
|
|
|
checkValidTransition: function (target)
|
|
|
|
{
|
|
|
|
// Not a valid target if it doesn't exist, isn't active or is already transitioning in or out
|
|
|
|
if (!target || target.sys.isActive() || target.sys.isTransitioning() || target === this.scene || this.systems.isTransitioning())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-04-13 17:59:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A single game step. This is only called if the parent Scene is transitioning
|
|
|
|
* out to another Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#step
|
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 17:59:00 +00:00
|
|
|
*
|
2018-09-13 07:09:44 +00:00
|
|
|
* @param {number} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
|
|
|
|
* @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.
|
2018-04-13 17:59:00 +00:00
|
|
|
*/
|
|
|
|
step: function (time, delta)
|
|
|
|
{
|
|
|
|
this._elapsed += delta;
|
|
|
|
|
2018-04-14 03:23:57 +00:00
|
|
|
this.transitionProgress = Clamp(this._elapsed / this._duration, 0, 1);
|
|
|
|
|
2018-04-13 19:12:29 +00:00
|
|
|
if (this._onUpdate)
|
|
|
|
{
|
2018-04-14 03:23:57 +00:00
|
|
|
this._onUpdate.call(this._onUpdateScope, this.transitionProgress);
|
2018-04-13 19:12:29 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 17:59:00 +00:00
|
|
|
if (this._elapsed >= this._duration)
|
|
|
|
{
|
2018-04-14 03:23:57 +00:00
|
|
|
this.transitionComplete();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by `step` when the transition out of this scene to another is over.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#transitionComplete
|
|
|
|
* @private
|
2019-01-18 12:19:41 +00:00
|
|
|
* @fires Phaser.Scenes.Events#TRANSITION_COMPLETE
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-14 03:23:57 +00:00
|
|
|
*/
|
|
|
|
transitionComplete: function ()
|
|
|
|
{
|
|
|
|
var targetSys = this._target.sys;
|
2018-04-15 22:14:56 +00:00
|
|
|
var targetSettings = this._target.sys.settings;
|
2018-04-14 03:23:57 +00:00
|
|
|
|
|
|
|
// Notify target scene
|
2019-01-18 12:19:41 +00:00
|
|
|
targetSys.events.emit(Events.TRANSITION_COMPLETE, this.scene);
|
2018-04-13 17:59:00 +00:00
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
// Clear target scene settings
|
|
|
|
targetSettings.isTransition = false;
|
|
|
|
targetSettings.transitionFrom = null;
|
2018-04-14 03:23:57 +00:00
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
// Clear local settings
|
2018-04-14 03:23:57 +00:00
|
|
|
this._duration = 0;
|
|
|
|
this._target = null;
|
|
|
|
this._onUpdate = null;
|
|
|
|
this._onUpdateScope = null;
|
2018-04-13 19:12:29 +00:00
|
|
|
|
2018-04-15 22:14:56 +00:00
|
|
|
// Now everything is clear we can handle what happens to this Scene
|
|
|
|
if (this._willRemove)
|
|
|
|
{
|
|
|
|
this.manager.remove(this.key);
|
|
|
|
}
|
|
|
|
else if (this._willSleep)
|
2018-04-14 03:23:57 +00:00
|
|
|
{
|
|
|
|
this.systems.sleep();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-13 17:59:00 +00:00
|
|
|
this.manager.stop(this.key);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {string} key - A unique key used to reference the Scene, i.e. `MainMenu` or `Level1`.
|
2022-10-04 17:48:21 +00:00
|
|
|
* @param {(Phaser.Types.Scenes.SceneType)} sceneConfig - The config for the Scene
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {boolean} [autoStart=false] - If `true` the Scene will be started immediately after being added.
|
|
|
|
* @param {object} [data] - Optional data object. This will be set as `Scene.settings.data` and passed to `Scene.init`, and `Scene.create`.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {?Phaser.Scene} The added Scene, if it was added immediately, otherwise `null`.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-11-06 14:38:36 +00:00
|
|
|
add: function (key, sceneConfig, autoStart, data)
|
2017-07-11 17:54:30 +00:00
|
|
|
{
|
2019-02-25 17:12:00 +00:00
|
|
|
return this.manager.add(key, sceneConfig, autoStart, data);
|
2017-07-11 17:54:30 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Launch the given Scene and run it in parallel with this one.
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-02-12 16:18:34 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#launch
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to launch.
|
2018-04-02 17:29:23 +00:00
|
|
|
* @param {object} [data] - The Scene data.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
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-07-09 13:08:55 +00:00
|
|
|
this.manager.queueOp('start', key, data);
|
2018-01-20 04:47:03 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-06-08 14:07:00 +00:00
|
|
|
/**
|
|
|
|
* Runs the given Scene, but does not change the state of this Scene.
|
2018-11-06 14:38:36 +00:00
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-06-08 14:07:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#run
|
|
|
|
* @since 3.10.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to run.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - A data object that will be passed to the Scene and emitted in its ready, wake, or resume events.
|
2018-06-08 14:07:00 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-06-08 14:07:00 +00:00
|
|
|
*/
|
|
|
|
run: function (key, data)
|
|
|
|
{
|
2018-07-09 13:08:55 +00:00
|
|
|
if (key && key !== this.key)
|
2018-06-08 14:07:00 +00:00
|
|
|
{
|
|
|
|
this.manager.queueOp('run', key, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 16:18:34 +00:00
|
|
|
/**
|
|
|
|
* Pause the Scene - this stops the update step from happening but it still renders.
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-02-12 16:18:34 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#pause
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to pause.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted in its pause event.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
pause: function (key, data)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-07-09 13:08:55 +00:00
|
|
|
this.manager.queueOp('pause', key, data);
|
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.
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-02-12 16:18:34 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#resume
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to resume.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted in its resume event.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
resume: function (key, data)
|
2017-06-30 02:31:31 +00:00
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-07-09 13:08:55 +00:00
|
|
|
this.manager.queueOp('resume', key, data);
|
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.
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-02-12 16:18:34 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#sleep
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to put to sleep.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted in its sleep event.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
sleep: function (key, data)
|
2017-06-30 02:31:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-07-09 13:08:55 +00:00
|
|
|
this.manager.queueOp('sleep', key, data);
|
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)
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-02-12 16:18:34 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#wake
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to wake up.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted in its wake event.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
wake: function (key, data)
|
2017-06-30 02:31:31 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2018-07-09 13:08:55 +00:00
|
|
|
this.manager.queueOp('wake', key, data);
|
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.
|
2020-01-03 21:35:07 +00:00
|
|
|
*
|
|
|
|
* This will happen at the next Scene Manager update, not immediately.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#switch
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to start.
|
2024-08-25 21:34:15 +00:00
|
|
|
* @param {any} [data] - Optional data object to pass to either the Scene `wake` or `start` method.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2024-08-25 21:34:15 +00:00
|
|
|
switch: function (key, data)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-01-20 04:47:03 +00:00
|
|
|
if (key !== this.key)
|
|
|
|
{
|
2024-08-25 21:34:15 +00:00
|
|
|
this.manager.queueOp('switch', this.key, key, data);
|
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.
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* This happens at the next Scene Manager update, not immediately.
|
|
|
|
*
|
2018-02-12 16:18:34 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#stop
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to stop.
|
2019-10-11 12:31:56 +00:00
|
|
|
* @param {any} [data] - Optional data object to pass to Scene.Systems.shutdown.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2019-10-11 12:31:56 +00:00
|
|
|
stop: function (key, data)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2017-06-30 02:31:31 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
2019-10-11 12:31:56 +00:00
|
|
|
this.manager.queueOp('stop', key, data);
|
2018-01-20 04:47:03 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {boolean} value - If `true` the Scene will be resumed. If `false` it will be paused.
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to set the active state of.
|
2018-06-26 15:08:14 +00:00
|
|
|
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted with its events.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-06-26 15:08:14 +00:00
|
|
|
setActive: function (value, key, data)
|
2018-01-20 04:47:03 +00:00
|
|
|
{
|
2018-05-01 11:35:56 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
var scene = this.manager.getScene(key);
|
|
|
|
|
|
|
|
if (scene)
|
|
|
|
{
|
2018-06-26 15:08:14 +00:00
|
|
|
scene.sys.setActive(value, data);
|
2018-05-01 11:35:56 +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
|
|
|
/**
|
|
|
|
* Sets the visible state of the given Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#setVisible
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2018-05-01 11:35:56 +00:00
|
|
|
* @param {boolean} value - The visible value.
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to set the visible state for.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
2018-05-01 11:35:56 +00:00
|
|
|
setVisible: function (value, key)
|
2017-02-08 01:07:01 +00:00
|
|
|
{
|
2018-05-01 11:35:56 +00:00
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
var scene = this.manager.getScene(key);
|
|
|
|
|
|
|
|
if (scene)
|
|
|
|
{
|
|
|
|
scene.sys.setVisible(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
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to check.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {boolean} Whether the Scene is sleeping, or `null` if no matching Scene was found.
|
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
|
|
|
/**
|
2019-02-27 20:19:55 +00:00
|
|
|
* Checks if the given Scene is running or not?
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#isActive
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to check.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {boolean} Whether the Scene is running, or `null` if no matching Scene was found.
|
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
|
|
|
|
2019-02-27 20:23:02 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given Scene is paused or not?
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#isPaused
|
|
|
|
* @since 3.17.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to check.
|
2019-02-27 20:23:02 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {boolean} Whether the Scene is paused, or `null` if no matching Scene was found.
|
2019-02-27 20:23:02 +00:00
|
|
|
*/
|
|
|
|
isPaused: function (key)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.isPaused(key);
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to check.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {boolean} Whether the Scene is visible, or `null` if no matching Scene was found.
|
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
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [keyA,keyB]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} keyA - The first Scene to swap.
|
|
|
|
* @param {(string|Phaser.Scene)} [keyB] - The second Scene to swap. If none is given it defaults to this Scene.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2024-08-23 15:50:47 +00:00
|
|
|
* Moves a Scene so it is immediately above another Scene in the Scenes list.
|
|
|
|
* If the Scene is already above the other, it isn't moved.
|
2018-04-02 17:29:23 +00:00
|
|
|
*
|
2024-08-23 15:50:47 +00:00
|
|
|
* This means it will render over the top of the other Scene.
|
2018-03-02 18:25:44 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#moveAbove
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [keyA,keyB]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} keyA - The Scene that Scene B will be moved to be above.
|
|
|
|
* @param {(string|Phaser.Scene)} [keyB] - The Scene to be moved. If none is given it defaults to this Scene.
|
2018-03-02 18:25:44 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-03-02 18:25:44 +00:00
|
|
|
*/
|
|
|
|
moveAbove: function (keyA, keyB)
|
|
|
|
{
|
|
|
|
if (keyB === undefined) { keyB = this.key; }
|
|
|
|
|
|
|
|
if (keyA !== keyB)
|
|
|
|
{
|
|
|
|
this.manager.moveAbove(keyA, keyB);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2024-08-23 15:50:47 +00:00
|
|
|
* Moves a Scene so it is immediately below another Scene in the Scenes list.
|
|
|
|
* If the Scene is already below the other, it isn't moved.
|
2018-04-02 17:29:23 +00:00
|
|
|
*
|
2024-08-23 15:50:47 +00:00
|
|
|
* This means it will render behind the other Scene.
|
2018-03-02 18:25:44 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#moveBelow
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [keyA,keyB]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} keyA - The Scene that Scene B will be moved to be below.
|
|
|
|
* @param {(string|Phaser.Scene)} [keyB] - The Scene to be moved. If none is given it defaults to this Scene.
|
2018-03-02 18:25:44 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-03-02 18:25:44 +00:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2020-01-03 21:35:07 +00:00
|
|
|
* If the SceneManager is processing the Scenes when this method is called it will
|
2018-03-02 03:50:55 +00:00
|
|
|
* queue the operation for the next update sequence.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#remove
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2019-01-02 10:54:39 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to be removed.
|
2018-03-02 03:50:55 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-03-02 03:50:55 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to move.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
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
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to move.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
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
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to move.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
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
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to move.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @return {this} This Scene Plugin instance.
|
2018-02-12 16:18:34 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2024-09-02 13:26:00 +00:00
|
|
|
* Retrieves a Scene based on the given key.
|
|
|
|
*
|
|
|
|
* If an actual Scene is passed to this method, it can be used to check if
|
|
|
|
* its currently within the Scene Manager, or not.
|
2018-02-12 16:18:34 +00:00
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
2024-11-04 11:56:55 +00:00
|
|
|
* @genericUse {T} - [$return]
|
2022-11-17 22:13:24 +00:00
|
|
|
*
|
2018-02-12 16:18:34 +00:00
|
|
|
* @method Phaser.Scenes.ScenePlugin#get
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2021-02-16 13:21:31 +00:00
|
|
|
* @param {(string|Phaser.Scene)} 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
|
|
|
},
|
|
|
|
|
2021-11-04 14:55:16 +00:00
|
|
|
/**
|
|
|
|
* Return the status of the Scene.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#getStatus
|
|
|
|
* @since 3.60.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2021-11-04 14:55:16 +00:00
|
|
|
* @param {(string|Phaser.Scene)} key - The Scene to get the status from.
|
|
|
|
*
|
|
|
|
* @return {number} The Scene status. This maps to the `Phaser.Scene` constants, such as `Phaser.Scene.LOADING`.
|
|
|
|
*/
|
|
|
|
getStatus: function (key)
|
|
|
|
{
|
|
|
|
var scene = this.manager.getScene(key);
|
|
|
|
|
|
|
|
if (scene)
|
|
|
|
{
|
|
|
|
return scene.sys.getStatus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-05-01 00:23:19 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the numeric index of a Scene in the Scenes list.
|
|
|
|
*
|
|
|
|
* @method Phaser.Scenes.ScenePlugin#getIndex
|
|
|
|
* @since 3.7.0
|
|
|
|
*
|
2022-11-17 22:13:24 +00:00
|
|
|
* @generic {Phaser.Scene} T
|
|
|
|
* @genericUse {(T|string)} - [key]
|
|
|
|
*
|
2018-05-01 00:23:19 +00:00
|
|
|
* @param {(string|Phaser.Scene)} [key] - The Scene to get the index of.
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @return {number} The index of the Scene.
|
2018-05-01 00:23:19 +00:00
|
|
|
*/
|
|
|
|
getIndex: function (key)
|
|
|
|
{
|
|
|
|
if (key === undefined) { key = this.key; }
|
|
|
|
|
|
|
|
return this.manager.getIndex(key);
|
|
|
|
},
|
|
|
|
|
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.
|
2021-02-16 13:21:31 +00:00
|
|
|
*
|
2018-04-13 16:12:17 +00:00
|
|
|
* 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;
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
eventEmitter.off(Events.SHUTDOWN, this.shutdown, this);
|
|
|
|
eventEmitter.off(Events.TRANSITION_OUT);
|
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.
|
2021-02-16 13:21:31 +00:00
|
|
|
*
|
2018-04-13 16:12:17 +00:00
|
|
|
* 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();
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
this.scene.sys.events.off(Events.START, this.start, this);
|
2018-04-13 16:12:17 +00:00
|
|
|
|
|
|
|
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-05-15 11:51:50 +00:00
|
|
|
PluginCache.register('ScenePlugin', ScenePlugin, 'scenePlugin');
|
2018-01-16 02:08:22 +00:00
|
|
|
|
2018-01-18 05:20:00 +00:00
|
|
|
module.exports = ScenePlugin;
|