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

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();
}
}
}
/**

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);
}
}
}

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++)
{

22
Plugins/IPlugin.js Normal file
View file

@ -0,0 +1,22 @@
// Module
var Shapes;
(function (Shapes) {
// Class
var Point = (function () {
// Constructor
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype.getDist = // Instance member
function () {
return Math.sqrt(this.x * this.x + this.y * this.y);
};
Point.origin = new Point(0, 0);
return Point;
})();
Shapes.Point = Point;
})(Shapes || (Shapes = {}));
// Local variables
var p = new Shapes.Point(3, 4);
var dist = p.getDist();

21
Plugins/IPlugin.ts Normal file
View file

@ -0,0 +1,21 @@
/// <reference path="../Phaser/Game.ts" />
module Phaser {
export interface IPlugin {
game: Game;
active: bool;
visible: bool;
preUpdate();
postUpdate();
preRender();
postRender();
destroy();
}
}

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -52,5 +52,17 @@
<TypeScriptIncludeComments>false</TypeScriptIncludeComments>
<TypeScriptSourceMap>false</TypeScriptSourceMap>
</PropertyGroup>
<ItemGroup>
<TypeScriptCompile Include="Template.ts" />
</ItemGroup>
<ItemGroup>
<Content Include="IPlugin.js">
<DependentUpon>IPlugin.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="IPlugin.ts" />
<Content Include="Template.js">
<DependentUpon>Template.ts</DependentUpon>
</Content>
</ItemGroup>
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
</Project>

53
Plugins/Template.js Normal file
View file

@ -0,0 +1,53 @@
var Phaser;
(function (Phaser) {
/// <reference path="../Phaser/Game.ts" />
/**
* Phaser - Example Plugin
*/
(function (Plugins) {
var Example = (function () {
function Example(game) {
this.game = game;
this.active = true;
this.visible = true;
}
Example.prototype.preUpdate = /**
* Pre-update is called at the start of the update cycle, before any other updates have taken place.
*/
function () {
};
Example.prototype.postUpdate = /**
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
*/
function () {
};
Example.prototype.preRender = /**
* 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
*/
function (camera) {
};
Example.prototype.render = /**
* 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
*/
function (camera) {
};
Example.prototype.postRender = /**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
*/
function (camera) {
};
Example.prototype.destroy = /**
* Clear down this Plugin and null out references
*/
function () {
this.game = null;
};
return Example;
})();
Plugins.Example = Example;
})(Phaser.Plugins || (Phaser.Plugins = {}));
var Plugins = Phaser.Plugins;
})(Phaser || (Phaser = {}));

72
Plugins/Template.ts Normal file
View file

@ -0,0 +1,72 @@
/// <reference path="../Phaser/Game.ts" />
/// <reference path="IPlugin.ts" />
/**
* Phaser - Example Plugin
*/
module Phaser.Plugins {
export class Example implements Phaser.IPlugin {
constructor(game: Phaser.Game) {
this.game = game;
this.active = true;
this.visible = true;
}
/**
* The essential reference to the main game object.
*/
public game: Game;
/**
* Controls whether preUpdate or postUpdate are called
*/
public active: bool;
/**
* Controls whether preRender or postRender are called
*/
public visible: bool;
/**
* Pre-update is called at the start of the update cycle, before any other updates have taken place.
* It is only called if active is set to true.
*/
public preUpdate() {
}
/**
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
* It is only called if active is set to true.
*/
public postUpdate() {
}
/**
* Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
* It is only called if visible is set to true.
*/
public preRender() {
}
/**
* Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run.
* It is only called if visible is set to true.
*/
public postRender() {
}
/**
* Clear down this Plugin and null out references
*/
public destroy() {
this.game = null;
}
}
}

View file

@ -9650,16 +9650,12 @@ var 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
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
function (camera) {
if(this.visible) {
for(var i = 0; i < this._length; i++) {
if(this._fx[i].preRender) {
this._fx[i].effect.preRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.preRender(camera);
}
}
}
@ -9667,16 +9663,12 @@ var Phaser;
CameraFX.prototype.render = /**
* 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
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
function (camera) {
if(this.visible) {
for(var i = 0; i < this._length; i++) {
if(this._fx[i].preRender) {
this._fx[i].effect.preRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.preRender(camera);
}
}
}
@ -9685,11 +9677,11 @@ var 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.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
function (camera) {
if(this.visible) {
for(var i = 0; i < this._length; i++) {
if(this._fx[i].postRender) {
this._fx[i].effect.postRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.postRender(camera);
}
}
}
@ -17648,14 +17640,14 @@ var Phaser;
this._dy -= group.transform.origin.y;
}
}
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) {
group.texture.context.fillStyle = group.texture.backgroundColor;
group.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
@ -17762,14 +17754,14 @@ var Phaser;
this._dy -= camera.transform.origin.y;
}
}
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) {
camera.texture.context.beginPath();
@ -17781,7 +17773,7 @@ var Phaser;
camera.texture.context.fillStyle = camera.texture.backgroundColor;
camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
}
//camera.fx.render(camera);
camera.fx.preRender(camera);
if(camera.texture.loaded) {
camera.texture.context.drawImage(camera.texture.texture, // Source Image
this._sx, // Source X (location within the source image)
@ -17797,7 +17789,7 @@ var Phaser;
return true;
};
CanvasRenderer.prototype.postRenderCamera = function (camera) {
//camera.fx.postRender(camera);
camera.fx.postRender(camera);
if(camera.modified || camera.texture.globalCompositeOperation) {
camera.texture.context.restore();
}
@ -17826,14 +17818,14 @@ var Phaser;
this._dy = camera.screenView.y + circle.y - camera.worldView.y;
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();
context.save();
context.lineWidth = lineWidth;
@ -18019,14 +18011,14 @@ var Phaser;
this._dy -= scrollZone.transform.origin.y;
}
}
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++) {
if(scrollZone.texture.isDynamic) {
scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
@ -18214,6 +18206,7 @@ var Phaser;
/// <reference path="renderers/HeadlessRenderer.ts" />
/// <reference path="renderers/CanvasRenderer.ts" />
/// <reference path="utils/DebugUtils.ts" />
/// <reference path="../Plugins/IPlugin.ts" />
/**
* Phaser - Game
*
@ -18418,6 +18411,20 @@ var Phaser;
// WebGL coming soon :)
}
};
Game.prototype.addPlugin = function (plugin) {
// Prototype?
if(typeof plugin === 'function') {
this.plugins.push(new plugin(this));
} else {
plugin.game = this;
this.plugins.push(plugin);
}
this._pluginsLength++;
};
Game.prototype.removePlugin = function (plugin) {
// TODO :)
this._pluginsLength--;
};
Game.prototype.loadComplete = /**
* Called when the load has finished after init was run.
*/
@ -18448,6 +18455,11 @@ var Phaser;
* Game loop method will be called when it's running.
*/
function () {
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();
@ -18460,6 +18472,16 @@ var Phaser;
this.onLoadUpdateCallback.call(this.callbackContext);
}
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);
}
@ -18469,6 +18491,11 @@ var Phaser;
} else if(this._loadComplete == false && this.onLoadRenderCallback) {
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();
}
}
};
Game.prototype.startState = /**
* Start current state.

43
build/phaser.d.ts vendored
View file

@ -4949,26 +4949,18 @@ 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): void;
public preRender(camera: Camera): void;
/**
* 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): void;
public render(camera: Camera): void;
/**
* 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): void;
public postRender(camera: Camera): void;
/**
* Clear down this FXManager and null out references
*/
@ -9383,6 +9375,18 @@ module Phaser {
static renderText(text: string, x: number, y: number, color?: string): void;
}
}
module Phaser {
interface IPlugin {
game: Game;
active: bool;
visible: bool;
preUpdate();
postUpdate();
preRender();
postRender();
destroy();
}
}
/**
* Phaser - Game
*
@ -9435,6 +9439,21 @@ module Phaser {
*/
private _pendingState;
/**
* Plugin loop pointer
* @type {number}
*/
private _p;
/**
* Plugins array counter
* @type {number}
*/
private _pluginsLength;
/**
* An Array of Phaser Plugins
* @type {Array}
*/
public plugins: IPlugin[];
/**
* The current State object (defaults to null)
* @type {State}
*/
@ -9581,6 +9600,8 @@ module Phaser {
*/
private boot(parent, width, height);
public setRenderer(type: number): void;
public addPlugin(plugin): void;
public removePlugin(plugin: IPlugin): void;
/**
* Called when the load has finished after init was run.
*/

View file

@ -9650,16 +9650,12 @@ var 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
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
function (camera) {
if(this.visible) {
for(var i = 0; i < this._length; i++) {
if(this._fx[i].preRender) {
this._fx[i].effect.preRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.preRender(camera);
}
}
}
@ -9667,16 +9663,12 @@ var Phaser;
CameraFX.prototype.render = /**
* 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
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
function (camera) {
if(this.visible) {
for(var i = 0; i < this._length; i++) {
if(this._fx[i].preRender) {
this._fx[i].effect.preRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.preRender(camera);
}
}
}
@ -9685,11 +9677,11 @@ var 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.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
function (camera) {
if(this.visible) {
for(var i = 0; i < this._length; i++) {
if(this._fx[i].postRender) {
this._fx[i].effect.postRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
this._fx[i].effect.postRender(camera);
}
}
}
@ -17648,14 +17640,14 @@ var Phaser;
this._dy -= group.transform.origin.y;
}
}
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) {
group.texture.context.fillStyle = group.texture.backgroundColor;
group.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
@ -17762,14 +17754,14 @@ var Phaser;
this._dy -= camera.transform.origin.y;
}
}
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) {
camera.texture.context.beginPath();
@ -17781,7 +17773,7 @@ var Phaser;
camera.texture.context.fillStyle = camera.texture.backgroundColor;
camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
}
//camera.fx.render(camera);
camera.fx.preRender(camera);
if(camera.texture.loaded) {
camera.texture.context.drawImage(camera.texture.texture, // Source Image
this._sx, // Source X (location within the source image)
@ -17797,7 +17789,7 @@ var Phaser;
return true;
};
CanvasRenderer.prototype.postRenderCamera = function (camera) {
//camera.fx.postRender(camera);
camera.fx.postRender(camera);
if(camera.modified || camera.texture.globalCompositeOperation) {
camera.texture.context.restore();
}
@ -17826,14 +17818,14 @@ var Phaser;
this._dy = camera.screenView.y + circle.y - camera.worldView.y;
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();
context.save();
context.lineWidth = lineWidth;
@ -18019,14 +18011,14 @@ var Phaser;
this._dy -= scrollZone.transform.origin.y;
}
}
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++) {
if(scrollZone.texture.isDynamic) {
scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
@ -18214,6 +18206,7 @@ var Phaser;
/// <reference path="renderers/HeadlessRenderer.ts" />
/// <reference path="renderers/CanvasRenderer.ts" />
/// <reference path="utils/DebugUtils.ts" />
/// <reference path="../Plugins/IPlugin.ts" />
/**
* Phaser - Game
*
@ -18418,6 +18411,20 @@ var Phaser;
// WebGL coming soon :)
}
};
Game.prototype.addPlugin = function (plugin) {
// Prototype?
if(typeof plugin === 'function') {
this.plugins.push(new plugin(this));
} else {
plugin.game = this;
this.plugins.push(plugin);
}
this._pluginsLength++;
};
Game.prototype.removePlugin = function (plugin) {
// TODO :)
this._pluginsLength--;
};
Game.prototype.loadComplete = /**
* Called when the load has finished after init was run.
*/
@ -18448,6 +18455,11 @@ var Phaser;
* Game loop method will be called when it's running.
*/
function () {
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();
@ -18460,6 +18472,16 @@ var Phaser;
this.onLoadUpdateCallback.call(this.callbackContext);
}
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);
}
@ -18469,6 +18491,11 @@ var Phaser;
} else if(this._loadComplete == false && this.onLoadRenderCallback) {
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();
}
}
};
Game.prototype.startState = /**
* Start current state.

View file

@ -0,0 +1,78 @@
static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') {
for (var s = 0; s < body.shapesLength; s++)
{
DebugUtils.context.beginPath();
if (body.shapes[s].type == Phaser.Physics.AdvancedPhysics.SHAPE_TYPE_POLY)
{
var verts = body.shapes[s].tverts;
// DebugUtils.context.moveTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
DebugUtils.context.moveTo(verts[0].x * 50, verts[0].y * 50);
for (var i = 1; i < verts.length; i++)
{
// DebugUtils.context.lineTo(body.position.x * 50 + verts[i].x, body.position.y * 50 + verts[i].y);
DebugUtils.context.lineTo(verts[i].x * 50, verts[i].y * 50);
}
// DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
DebugUtils.context.lineTo(verts[0].x * 50, verts[0].y * 50);
}
else if (body.shapes[s].type == Phaser.Physics.AdvancedPhysics.SHAPE_TYPE_CIRCLE)
{
var circle = <Phaser.Physics.Shapes.Circle> body.shapes[s];
DebugUtils.context.arc(circle.tc.x * 50, circle.tc.y * 50, circle.radius * 50, 0, Math.PI * 2, false);
}
DebugUtils.context.closePath();
if (body.isAwake)
{
DebugUtils.context.fillStyle = fillStyle;
}
else
{
DebugUtils.context.fillStyle = sleepStyle;
}
DebugUtils.context.fill();
}
}
/**
* Render debug infos. (including name, bounds info, position and some other properties)
* @param x {number} X position of the debug info to be rendered.
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
/*
static renderPhysicsBodyInfo(body: Phaser.Physics.Body, x: number, y: number, color?: string = 'rgb(255,255,255)') {
DebugUtils.context.fillStyle = color;
DebugUtils.context.fillText('Body ID: ' + body.name, x, y);
DebugUtils.context.fillText('Position x: ' + body.position.x.toFixed(1) + ' y: ' + body.position.y.toFixed(1) + ' rotation: ' + body.angle.toFixed(1), x, y + 14);
DebugUtils.context.fillText('World x: ' + (body.position.x * 50).toFixed(1) + ' y: ' + (body.position.y * 50).toFixed(1), x, y + 28);
DebugUtils.context.fillText('Velocity x: ' + body.velocity.x.toFixed(1) + ' y: ' + body.velocity.y.toFixed(1), x, y + 42);
if (body.shapes[0].verts.length > 0)
{
DebugUtils.context.fillText('Vert 1 x: ' + (body.shapes[0].verts[0].x * 50) + ' y: ' + (body.shapes[0].verts[0].y * 50), x, y + 56);
DebugUtils.context.fillText('Vert 2 x: ' + (body.shapes[0].verts[1].x * 50) + ' y: ' + (body.shapes[0].verts[1].y * 50), x, y + 70);
DebugUtils.context.fillText('Vert 3 x: ' + (body.shapes[0].tverts[2].x * 50) + ' y: ' + (body.shapes[0].tverts[2].y * 50), x, y + 84);
DebugUtils.context.fillText('Vert 4 x: ' + (body.shapes[0].tverts[3].x * 50) + ' y: ' + (body.shapes[0].tverts[3].y * 50), x, y + 98);
//
// DebugUtils.context.fillText('Vert 1 x: ' + body.shapes[0].verts[0].x.toFixed(1) + ' y: ' + body.shapes[0].verts[0].y.toFixed(1), x, y + 56);
// DebugUtils.context.fillText('Vert 2 x: ' + body.shapes[0].verts[1].x.toFixed(1) + ' y: ' + body.shapes[0].verts[1].y.toFixed(1), x, y + 70);
// DebugUtils.context.fillText('Vert 3 x: ' + body.shapes[0].verts[2].x.toFixed(1) + ' y: ' + body.shapes[0].verts[2].y.toFixed(1), x, y + 84);
// DebugUtils.context.fillText('Vert 4 x: ' + body.shapes[0].verts[3].x.toFixed(1) + ' y: ' + body.shapes[0].verts[3].y.toFixed(1), x, y + 98);
//
}
}
*/