Merge pull request #160 from cocoademon/camera_shake

Add a postUpdate function to plugins
This commit is contained in:
Richard Davey
2013-11-03 18:58:04 -08:00
3 changed files with 37 additions and 0 deletions
+1
View File
@@ -437,6 +437,7 @@ Phaser.Game.prototype = {
this.plugins.update();
this.world.postUpdate();
this.plugins.postUpdate();
this.renderer.render(this.stage._stage);
this.plugins.render();
+6
View File
@@ -50,6 +50,12 @@ Phaser.Plugin = function (game, parent) {
* @default
*/
this.hasUpdate = false;
/**
* @property {boolean} hasPostUpdate - A flag to indicate if this plugin has a postUpdate method.
* @default
*/
this.hasPostUpdate = false;
/**
* @property {boolean} hasRender - A flag to indicate if this plugin has a render method.
+30
View File
@@ -77,6 +77,12 @@ Phaser.PluginManager.prototype = {
result = true;
}
if (typeof plugin['postUpdate'] === 'function')
{
plugin.hasPostUpdate = true;
result = true;
}
if (typeof plugin['render'] === 'function')
{
plugin.hasRender = true;
@@ -176,6 +182,30 @@ Phaser.PluginManager.prototype = {
},
/**
* PostUpdate is the last thing to be called before the world render.
* In particular, it is called after the world postUpdate, which means the camera has been adjusted.
* It only calls plugins who have active=true.
*
* @method Phaser.PluginManager#postUpdate
*/
postUpdate: function () {
if (this._pluginsLength == 0)
{
return;
}
for (this._p = 0; this._p < this._pluginsLength; this._p++)
{
if (this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate)
{
this.plugins[this._p].postUpdate();
}
}
},
/**
* Render is called right after the Game Renderer completes, but before the State.render.
* It only calls plugins who have visible=true.