var Class = require('../utils/Class'); var PluginCache = require('../plugins/PluginCache'); var SceneEvents = require('../scene/events'); var GameObjectFactory = new Class({ initialize: function GameObjectFactory(scene){ this.scene = scene; this.systems = scene.sys; this.displayList; this.updateList; scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); } , boot: function (){ this.displayList = this.systems.displayList; this.updateList = this.systems.updateList; this.systems.events.once(SceneEvents.DESTROY, this.destroy, this); } , start: function (){ this.systems.events.once(SceneEvents.SHUTDOWN, this.shutdown, this); } , existing: function (child){ if (child.renderCanvas || child.renderWebGL) { this.displayList.add(child); } if (child.preUpdate) { this.updateList.add(child); } return child; } , shutdown: function (){ this.systems.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); } , destroy: function (){ this.shutdown(); this.scene.sys.events.off(SceneEvents.START, this.start, this); this.scene = null ; this.systems = null ; this.displayList = null ; this.updateList = null ; } } ); GameObjectFactory.register = function (factoryType, factoryFunction){ if (!GameObjectFactory.prototype.hasOwnProperty(factoryType)) { GameObjectFactory.prototype[factoryType] = factoryFunction; } } ; GameObjectFactory.remove = function (factoryType){ if (GameObjectFactory.prototype.hasOwnProperty(factoryType)) { delete GameObjectFactory.prototype[factoryType]; } } ; PluginCache.register('GameObjectFactory', GameObjectFactory, 'add'); module.exports = GameObjectFactory;