2018-01-16 19:49:13 +00:00
|
|
|
var Class = require('../utils/Class');
|
|
|
|
var PluginManager = require('../plugins/PluginManager');
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class GameObjectFactory
|
|
|
|
* @memberOf Phaser.GameObjects
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs.
|
|
|
|
*/
|
2017-09-14 00:32:10 +00:00
|
|
|
var GameObjectFactory = new Class({
|
2017-07-04 00:59:31 +00:00
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function GameObjectFactory (scene)
|
2017-07-04 00:59:31 +00:00
|
|
|
{
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* The Scene to which this Game Object belongs.
|
|
|
|
* Game Objects can only belong to one Scene.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.GameObjectFactory#scene
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
* @protected
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene = scene;
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* A reference to the Scene.Systems.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.GameObjectFactory#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
|
|
|
|
2017-08-15 22:37:38 +00:00
|
|
|
this.displayList;
|
2018-02-01 05:48:56 +00:00
|
|
|
|
2017-08-15 22:37:38 +00:00
|
|
|
this.updateList;
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* Boots the plugin.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.GameObjectFactory#boot
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-16 02:08:22 +00:00
|
|
|
boot: function ()
|
2017-08-15 22:37:38 +00:00
|
|
|
{
|
2018-01-16 02:08:22 +00:00
|
|
|
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);
|
2017-07-04 00:59:31 +00:00
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* Adds an existing Game Object to this Scene.
|
|
|
|
*
|
|
|
|
* If the Game Object renders, it will be added to the Display List.
|
|
|
|
* If it has a `preUpdate` method, it will be added to the Update List.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.GameObjectFactory#existing
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.GameObject} child - The child to be added to this Scene.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that was added.
|
|
|
|
*/
|
2017-07-05 00:21:47 +00:00
|
|
|
existing: function (child)
|
|
|
|
{
|
|
|
|
if (child.renderCanvas || child.renderWebGL)
|
|
|
|
{
|
|
|
|
this.displayList.add(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child.preUpdate)
|
|
|
|
{
|
|
|
|
this.updateList.add(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* Shuts this plugin down.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.GameObjectFactory#shutdown
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-16 02:08:22 +00:00
|
|
|
shutdown: function ()
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* Destroys this plugin.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.GameObjectFactory#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-09-14 00:32:10 +00:00
|
|
|
destroy: function ()
|
2017-07-04 00:59:31 +00:00
|
|
|
{
|
2017-09-14 00:32:10 +00:00
|
|
|
this.scene = null;
|
|
|
|
this.displayList = null;
|
|
|
|
this.updateList = null;
|
|
|
|
}
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2017-09-14 00:32:10 +00:00
|
|
|
});
|
2017-07-27 16:40:15 +00:00
|
|
|
|
2017-09-14 01:27:29 +00:00
|
|
|
// Static method called directly by the Game Object factory functions
|
2017-08-03 03:06:13 +00:00
|
|
|
|
2017-09-14 00:32:10 +00:00
|
|
|
GameObjectFactory.register = function (type, factoryFunction)
|
|
|
|
{
|
|
|
|
if (!GameObjectFactory.prototype.hasOwnProperty(type))
|
2017-08-11 12:22:41 +00:00
|
|
|
{
|
2017-09-14 00:32:10 +00:00
|
|
|
GameObjectFactory.prototype[type] = factoryFunction;
|
2017-09-13 15:06:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-18 05:18:09 +00:00
|
|
|
PluginManager.register('GameObjectFactory', GameObjectFactory, 'add');
|
2018-01-16 02:08:22 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
module.exports = GameObjectFactory;
|