mirror of
https://github.com/photonstorm/phaser
synced 2025-01-05 09:48:49 +00:00
6b2307594a
Every Plugin has been updated to correctly follow the same flow through the Scene lifecycle. Instead of listening for the Scene 'boot' event, which is only dispatched once (when the Scene is first created), they will now listen for the Scene 'start' event, which occurs every time the Scene is started. All plugins now consistently follow the same Shutdown and Destroy patterns too, meaning they tidy-up after themselves on a shutdown, not just a destroy. Overall, this change means that there should be less issues when returning to previously closed Scenes, as the plugins will restart themselves properly.
144 lines
3.9 KiB
JavaScript
144 lines
3.9 KiB
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
*/
|
|
|
|
var Class = require('../utils/Class');
|
|
var PluginManager = require('../boot/PluginManager');
|
|
|
|
/**
|
|
* @classdesc
|
|
* The Game Object Creator is a Scene plugin that allows you to quickly create many common
|
|
* types of Game Objects and return them. Unlike the Game Object Factory, they are not automatically
|
|
* added to the Scene.
|
|
*
|
|
* Game Objects directly register themselves with the Creator and inject their own creation
|
|
* methods into the class.
|
|
*
|
|
* @class GameObjectCreator
|
|
* @memberOf Phaser.GameObjects
|
|
* @constructor
|
|
* @since 3.0.0
|
|
*
|
|
* @param {Phaser.Scene} scene - The Scene to which this Game Object Factory belongs.
|
|
*/
|
|
var GameObjectCreator = new Class({
|
|
|
|
initialize:
|
|
|
|
function GameObjectCreator (scene)
|
|
{
|
|
/**
|
|
* The Scene to which this Game Object Creator belongs.
|
|
*
|
|
* @name Phaser.GameObjects.GameObjectCreator#scene
|
|
* @type {Phaser.Scene}
|
|
* @protected
|
|
* @since 3.0.0
|
|
*/
|
|
this.scene = scene;
|
|
|
|
/**
|
|
* A reference to the Scene.Systems.
|
|
*
|
|
* @name Phaser.GameObjects.GameObjectCreator#systems
|
|
* @type {Phaser.Scenes.Systems}
|
|
* @protected
|
|
* @since 3.0.0
|
|
*/
|
|
this.systems = scene.sys;
|
|
|
|
/**
|
|
* A reference to the Scene Display List.
|
|
*
|
|
* @name Phaser.GameObjects.GameObjectCreator#displayList
|
|
* @type {Phaser.GameObjects.DisplayList}
|
|
* @protected
|
|
* @since 3.0.0
|
|
*/
|
|
this.displayList;
|
|
|
|
/**
|
|
* A reference to the Scene Update List.
|
|
*
|
|
* @name Phaser.GameObjects.GameObjectCreator#updateList;
|
|
* @type {Phaser.GameObjects.UpdateList}
|
|
* @protected
|
|
* @since 3.0.0
|
|
*/
|
|
this.updateList;
|
|
|
|
scene.sys.events.on('start', this.start, this);
|
|
},
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @method Phaser.GameObjects.GameObjectCreator#start
|
|
* @private
|
|
* @since 3.4.1
|
|
*/
|
|
start: function ()
|
|
{
|
|
this.displayList = this.systems.displayList;
|
|
this.updateList = this.systems.updateList;
|
|
|
|
var eventEmitter = this.systems.events;
|
|
|
|
eventEmitter.once('shutdown', this.shutdown, this);
|
|
eventEmitter.once('destroy', this.destroy, this);
|
|
},
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @method Phaser.GameObjects.GameObjectCreator#shutdown
|
|
* @private
|
|
* @since 3.0.0
|
|
*/
|
|
shutdown: function ()
|
|
{
|
|
var eventEmitter = this.systems.events;
|
|
|
|
eventEmitter.off('shutdown', this.shutdown, this);
|
|
},
|
|
|
|
/**
|
|
* The Scene that owns this plugin is being destroyed.
|
|
* We need to shutdown and then kill off all external references.
|
|
*
|
|
* @method Phaser.GameObjects.GameObjectCreator#destroy
|
|
* @private
|
|
* @since 3.0.0
|
|
*/
|
|
destroy: function ()
|
|
{
|
|
this.shutdown();
|
|
|
|
this.scene.sys.events.off('start', this.start, this);
|
|
|
|
this.scene = null;
|
|
this.systems = null;
|
|
this.displayList = null;
|
|
this.updateList = null;
|
|
}
|
|
|
|
});
|
|
|
|
// Static method called directly by the Game Object creator functions
|
|
|
|
GameObjectCreator.register = function (factoryType, factoryFunction)
|
|
{
|
|
if (!GameObjectCreator.prototype.hasOwnProperty(factoryType))
|
|
{
|
|
GameObjectCreator.prototype[factoryType] = factoryFunction;
|
|
}
|
|
};
|
|
|
|
PluginManager.register('GameObjectCreator', GameObjectCreator, 'make');
|
|
|
|
module.exports = GameObjectCreator;
|