Plugin Support added and CameraFX re-enabled

This commit is contained in:
Richard Davey
2013-08-02 19:37:43 +01:00
parent 982faeedb8
commit f3dcd3e831
12 changed files with 556 additions and 156 deletions
+75
View File
@@ -27,6 +27,7 @@
/// <reference path="renderers/HeadlessRenderer.ts" />
/// <reference path="renderers/CanvasRenderer.ts" />
/// <reference path="utils/DebugUtils.ts" />
/// <reference path="../Plugins/IPlugin.ts" />
/**
* Phaser - Game
@@ -107,6 +108,24 @@ module Phaser {
*/
private _pendingState = null;
/**
* Plugin loop pointer
* @type {number}
*/
private _p: number;
/**
* Plugins array counter
* @type {number}
*/
private _pluginsLength: number;
/**
* An Array of Phaser Plugins
* @type {Array}
*/
public plugins: Phaser.IPlugin[];
/**
* The current State object (defaults to null)
* @type {State}
@@ -366,6 +385,30 @@ module Phaser {
}
public addPlugin(plugin) {
// Prototype?
if (typeof plugin === 'function')
{
this.plugins.push(new plugin(this));
}
else
{
plugin.game = this;
this.plugins.push(plugin);
}
this._pluginsLength++;
}
public removePlugin(plugin: Phaser.IPlugin) {
// TODO :)
this._pluginsLength--;
}
/**
* Called when the load has finished after init was run.
*/
@@ -406,6 +449,14 @@ module Phaser {
*/
private loop() {
for (this._p = 0; this._p < this._pluginsLength; this._p++)
{
if (this.plugins[this._p].active)
{
this.plugins[this._p].preUpdate();
}
}
this.tweens.update();
this.input.update();
this.stage.update();
@@ -424,6 +475,22 @@ module Phaser {
this.world.postUpdate();
for (this._p = 0; this._p < this._pluginsLength; this._p++)
{
if (this.plugins[this._p].active)
{
this.plugins[this._p].postUpdate();
}
}
for (this._p = 0; this._p < this._pluginsLength; this._p++)
{
if (this.plugins[this._p].visible)
{
this.plugins[this._p].preRender();
}
}
if (this._loadComplete && this.onPreRenderCallback)
{
this.onPreRenderCallback.call(this.callbackContext);
@@ -440,6 +507,14 @@ module Phaser {
this.onLoadRenderCallback.call(this.callbackContext);
}
for (this._p = 0; this._p < this._pluginsLength; this._p++)
{
if (this.plugins[this._p].visible)
{
this.plugins[this._p].postRender();
}
}
}
/**
+6 -14
View File
@@ -158,12 +158,8 @@ module Phaser {
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
* @param {Camera} camera
* @param {number} cameraX
* @param {number} cameraY
* @param {number} cameraWidth
* @param {number} cameraHeight
*/
public preRender(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
public preRender(camera:Camera) {
if (this.visible)
{
@@ -171,7 +167,7 @@ module Phaser {
{
if (this._fx[i].preRender)
{
this._fx[i].effect.preRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.preRender(camera);
}
}
}
@@ -181,12 +177,8 @@ module Phaser {
/**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
* @param {Camera} camera
* @param {number} cameraX
* @param {number} cameraY
* @param {number} cameraWidth
* @param {number} cameraHeight
*/
public render(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
public render(camera:Camera) {
if (this.visible)
{
@@ -194,7 +186,7 @@ module Phaser {
{
if (this._fx[i].preRender)
{
this._fx[i].effect.preRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.preRender(camera);
}
}
}
@@ -205,7 +197,7 @@ module Phaser {
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
public postRender(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
public postRender(camera:Camera) {
if (this.visible)
{
@@ -213,7 +205,7 @@ module Phaser {
{
if (this._fx[i].postRender)
{
this._fx[i].effect.postRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.postRender(camera);
}
}
}
+34 -34
View File
@@ -169,14 +169,14 @@ module Phaser {
}
}
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
this._sw = Math.round(this._sw);
this._sh = Math.round(this._sh);
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
this._sx = Math.floor(this._sx);
this._sy = Math.floor(this._sy);
this._sw = Math.floor(this._sw);
this._sh = Math.floor(this._sh);
this._dx = Math.floor(this._dx);
this._dy = Math.floor(this._dy);
this._dw = Math.floor(this._dw);
this._dh = Math.floor(this._dh);
if (group.texture.opaque)
{
@@ -326,14 +326,14 @@ module Phaser {
}
}
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
this._sw = Math.round(this._sw);
this._sh = Math.round(this._sh);
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
this._sx = Math.floor(this._sx);
this._sy = Math.floor(this._sy);
this._sw = Math.floor(this._sw);
this._sh = Math.floor(this._sh);
this._dx = Math.floor(this._dx);
this._dy = Math.floor(this._dy);
this._dw = Math.floor(this._dw);
this._dh = Math.floor(this._dh);
// Clip the camera so we don't get sprites appearing outside the edges
if (camera.clip == true && camera.disableClipping == false)
@@ -350,7 +350,7 @@ module Phaser {
camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
}
//camera.fx.render(camera);
camera.fx.preRender(camera);
if (camera.texture.loaded)
{
@@ -373,7 +373,7 @@ module Phaser {
public postRenderCamera(camera: Camera) {
//camera.fx.postRender(camera);
camera.fx.postRender(camera);
if (camera.modified || camera.texture.globalCompositeOperation)
{
@@ -406,14 +406,14 @@ module Phaser {
this._dw = circle.diameter;
this._dh = circle.diameter;
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
this._sw = Math.round(this._sw);
this._sh = Math.round(this._sh);
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
this._sx = Math.floor(this._sx);
this._sy = Math.floor(this._sy);
this._sw = Math.floor(this._sw);
this._sh = Math.floor(this._sh);
this._dx = Math.floor(this._dx);
this._dy = Math.floor(this._dy);
this._dw = Math.floor(this._dw);
this._dh = Math.floor(this._dh);
this._game.stage.saveCanvasValues();
@@ -669,14 +669,14 @@ module Phaser {
}
}
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
this._sw = Math.round(this._sw);
this._sh = Math.round(this._sh);
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
this._sx = Math.floor(this._sx);
this._sy = Math.floor(this._sy);
this._sw = Math.floor(this._sw);
this._sh = Math.floor(this._sh);
this._dx = Math.floor(this._dx);
this._dy = Math.floor(this._dy);
this._dw = Math.floor(this._dw);
this._dh = Math.floor(this._dh);
for (var i = 0; i < scrollZone.regions.length; i++)
{