Phaser.PluginManager = function (game){ this.game = game; this.plugins = [] ; this._len = 0; this._i = 0; } ; Phaser.PluginManager.prototype = { add: function (plugin){ var args = Array.prototype.splice.call(arguments, 1); var result = false ; if (typeof plugin === 'function') { plugin = new plugin(this.game, this); } else { plugin.game = this.game; plugin.parent = this; } if (typeof plugin.preUpdate === 'function') { plugin.hasPreUpdate = true ; result = true ; } if (typeof plugin.update === 'function') { plugin.hasUpdate = true ; result = true ; } if (typeof plugin.postUpdate === 'function') { plugin.hasPostUpdate = true ; result = true ; } if (typeof plugin.render === 'function') { plugin.hasRender = true ; result = true ; } if (typeof plugin.postRender === 'function') { plugin.hasPostRender = true ; result = true ; } if (result) { if (plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) { plugin.active = true ; } if (plugin.hasRender || plugin.hasPostRender) { plugin.visible = true ; } this._len = this.plugins.push(plugin); if (typeof plugin.init === 'function') { plugin.init.apply(plugin, args); } return plugin; } else { return null ; } } , remove: function (plugin){ this._i = this._len; while (this._i-- ){ if (this.plugins[this._i] === plugin) { plugin.destroy(); this.plugins.splice(this._i, 1); this._len-- ; return ; } } } , removeAll: function (){ this._i = this._len; while (this._i-- ){ this.plugins[this._i].destroy(); } this.plugins.length = 0; this._len = 0; } , preUpdate: function (){ this._i = this._len; while (this._i-- ){ if (this.plugins[this._i].active && this.plugins[this._i].hasPreUpdate) { this.plugins[this._i].preUpdate(); } } } , update: function (){ this._i = this._len; while (this._i-- ){ if (this.plugins[this._i].active && this.plugins[this._i].hasUpdate) { this.plugins[this._i].update(); } } } , postUpdate: function (){ this._i = this._len; while (this._i-- ){ if (this.plugins[this._i].active && this.plugins[this._i].hasPostUpdate) { this.plugins[this._i].postUpdate(); } } } , render: function (){ this._i = this._len; while (this._i-- ){ if (this.plugins[this._i].visible && this.plugins[this._i].hasRender) { this.plugins[this._i].render(); } } } , postRender: function (){ this._i = this._len; while (this._i-- ){ if (this.plugins[this._i].visible && this.plugins[this._i].hasPostRender) { this.plugins[this._i].postRender(); } } } , destroy: function (){ this.removeAll(); this.game = null ; } } ; Phaser.PluginManager.prototype.constructor = Phaser.PluginManager;