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-02-12 23:03:48 +00:00
|
|
|
var PluginManager = require('../boot/PluginManager');
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2018-02-06 15:04:20 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* @classdesc
|
2018-02-06 15:04:20 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2017-09-14 01:27:29 +00:00
|
|
|
var GameObjectCreator = new Class({
|
2017-07-04 00:59:31 +00:00
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function GameObjectCreator (scene)
|
2017-07-04 00:59:31 +00:00
|
|
|
{
|
2018-02-06 15:04:20 +00:00
|
|
|
/**
|
|
|
|
* The Scene to which this Game Object Creator belongs.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.GameObjectCreator#scene
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
* @protected
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene = scene;
|
2017-11-17 13:30:53 +00:00
|
|
|
|
2018-02-06 15:04:20 +00:00
|
|
|
/**
|
|
|
|
* A reference to the Scene.Systems.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.GameObjectCreator#systems
|
|
|
|
* @type {Phaser.Scenes.Systems}
|
|
|
|
* @protected
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-16 02:08:22 +00:00
|
|
|
this.systems = scene.sys;
|
|
|
|
|
2018-01-18 14:00:31 +00:00
|
|
|
if (!scene.sys.settings.isBooted)
|
|
|
|
{
|
|
|
|
scene.sys.events.once('boot', this.boot, this);
|
|
|
|
}
|
2018-01-16 02:08:22 +00:00
|
|
|
|
2018-02-06 15:04:20 +00:00
|
|
|
/**
|
|
|
|
* A reference to the Scene Display List.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.GameObjectCreator#displayList
|
|
|
|
* @type {Phaser.GameObjects.DisplayList}
|
|
|
|
* @protected
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 13:30:53 +00:00
|
|
|
this.displayList;
|
2018-02-06 15:04:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A reference to the Scene Update List.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.GameObjectCreator#updateList;
|
|
|
|
* @type {Phaser.GameObjects.UpdateList}
|
|
|
|
* @protected
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 13:30:53 +00:00
|
|
|
this.updateList;
|
|
|
|
},
|
|
|
|
|
2018-02-06 15:04:20 +00:00
|
|
|
/**
|
|
|
|
* Boots the plugin.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.GameObjectCreator#boot
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-16 02:08:22 +00:00
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
this.displayList = this.systems.displayList;
|
|
|
|
this.updateList = this.systems.updateList;
|
|
|
|
|
2018-01-18 14:00:31 +00:00
|
|
|
var eventEmitter = this.systems.events;
|
|
|
|
|
|
|
|
eventEmitter.on('shutdown', this.shutdown, this);
|
|
|
|
eventEmitter.on('destroy', this.destroy, this);
|
2018-01-16 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 15:04:20 +00:00
|
|
|
/**
|
|
|
|
* Shuts this plugin down.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.GameObjectCreator#shutdown
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-16 02:08:22 +00:00
|
|
|
shutdown: function ()
|
2017-11-17 13:30:53 +00:00
|
|
|
{
|
2017-07-04 00:59:31 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 15:04:20 +00:00
|
|
|
/**
|
|
|
|
* Destroys this plugin.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.GameObjectCreator#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-09-14 01:27:29 +00:00
|
|
|
destroy: function ()
|
2017-07-04 00:59:31 +00:00
|
|
|
{
|
2017-09-14 01:27:29 +00:00
|
|
|
this.scene = null;
|
2017-11-17 13:30:53 +00:00
|
|
|
this.displayList = null;
|
|
|
|
this.updateList = null;
|
2017-09-14 01:27:29 +00:00
|
|
|
}
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2017-09-14 01:27:29 +00:00
|
|
|
});
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2017-09-14 01:27:29 +00:00
|
|
|
// Static method called directly by the Game Object creator functions
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2018-03-19 13:45:00 +00:00
|
|
|
GameObjectCreator.register = function (factoryType, factoryFunction)
|
2017-09-14 01:27:29 +00:00
|
|
|
{
|
2018-03-19 13:45:00 +00:00
|
|
|
if (!GameObjectCreator.prototype.hasOwnProperty(factoryType))
|
2017-08-11 12:22:41 +00:00
|
|
|
{
|
2018-03-19 13:45:00 +00:00
|
|
|
GameObjectCreator.prototype[factoryType] = factoryFunction;
|
2017-07-04 00:59:31 +00:00
|
|
|
}
|
2017-09-13 15:06:05 +00:00
|
|
|
};
|
|
|
|
|
2018-01-18 05:18:09 +00:00
|
|
|
PluginManager.register('GameObjectCreator', GameObjectCreator, 'make');
|
2018-01-16 02:08:22 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
module.exports = GameObjectCreator;
|