Skip to content

Commit

Permalink
Lots of updates across input, rendering and grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed May 17, 2013
1 parent a6e8436 commit 5556859
Show file tree
Hide file tree
Showing 40 changed files with 840 additions and 479 deletions.
4 changes: 4 additions & 0 deletions Phaser/AnimationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Phaser {
* Local private reference to game.
*/
private _game: Game;

/**
* Local private reference to its owner sprite.
*/
Expand All @@ -43,11 +44,13 @@ module Phaser {
* Animation key-value container.
*/
private _anims: {};

/**
* Index of current frame.
* @type {number}
*/
private _frameIndex: number;

/**
* Data contains animation frames.
* @type {FrameData}
Expand All @@ -58,6 +61,7 @@ module Phaser {
* Keeps track of the current animation being played.
*/
public currentAnim: Animation;

/**
* Keeps track of the current frame of animation.
*/
Expand Down
16 changes: 14 additions & 2 deletions Phaser/Basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module Phaser {
this.visible = true;
this.alive = true;
this.isGroup = false;
this.ignoreGlobalUpdate = false;
this.ignoreGlobalRender = false;
this.ignoreDrawDebug = false;

}
Expand Down Expand Up @@ -70,6 +72,16 @@ module Phaser {
*/
public alive: bool;

/**
* Setting this to true will prevent the object from being updated during the main game loop (you will have to call update on it yourself)
*/
public ignoreGlobalUpdate: bool;

/**
* Setting this to true will prevent the object from being rendered during the main game loop (you will have to call render on it yourself)
*/
public ignoreGlobalRender: bool;

/**
* Setting this to true will prevent the object from appearing
* when the visual debug mode in the debugger overlay is toggled on.
Expand All @@ -93,7 +105,7 @@ module Phaser {
* Override this to update your class's position and appearance.
* This is where most of your game rules and behavioral code will go.
*/
public update() {
public update(forceUpdate?: bool = false) {
}

/**
Expand All @@ -102,7 +114,7 @@ module Phaser {
public postUpdate() {
}

public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number, forceRender?: bool = false) {
}

/**
Expand Down
26 changes: 26 additions & 0 deletions Phaser/DynamicTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ module Phaser {

}

/**
* Given an array of GameObjects it will update each of them so that their canvas/contexts reference this DynamicTexture
* @param objects {Array} An array of GameObjects, or objects that inherit from it such as Sprites
*/
public assignCanvasToGameObjects(objects: GameObject[]) {

for (var i = 0; i < objects.length; i++)
{
objects[i].canvas = this.canvas;
objects[i].context = this.context;
}

}

/**
* Clear the whole canvas.
*/
Expand All @@ -248,6 +262,18 @@ module Phaser {

}

/**
* Renders this DynamicTexture to the Stage at the given x/y coordinates
*
* @param x {number} The X coordinate to render on the stage to (given in screen coordinates, not world)
* @param y {number} The Y coordinate to render on the stage to (given in screen coordinates, not world)
*/
public render(x?: number = 0, y?: number = 0) {

this._game.stage.context.drawImage(this.canvas, x, y);

}

public get width(): number {
return this.bounds.width;
}
Expand Down
6 changes: 3 additions & 3 deletions Phaser/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,11 @@ module Phaser {
/**
* Create a new object container.
*
* @param MaxSize {number} Optional, capacity of this group.
* @param maxSize {number} Optional, capacity of this group.
* @returns {Group} The newly created group.
*/
public createGroup(MaxSize?: number = 0): Group {
return this.world.createGroup(MaxSize);
public createGroup(maxSize?: number = 0): Group {
return this.world.createGroup(maxSize);
}

/**
Expand Down
24 changes: 17 additions & 7 deletions Phaser/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ module Phaser {
/**
* Automatically goes through and calls update on everything you added.
*/
public update() {
public update(forceUpdate?: bool = false) {

if (this.ignoreGlobalUpdate && forceUpdate == false)
{
return;
}

var basic: Basic;
var i: number = 0;
Expand All @@ -107,10 +112,10 @@ module Phaser {
{
basic = this.members[i++];

if ((basic != null) && basic.exists && basic.active)
if ((basic != null) && basic.exists && basic.active && basic.ignoreGlobalUpdate == false)
{
basic.preUpdate();
basic.update();
basic.update(forceUpdate);
basic.postUpdate();
}
}
Expand All @@ -119,7 +124,12 @@ module Phaser {
/**
* Automatically goes through and calls render on everything you added.
*/
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number, forceRender?: bool = false) {

if (this.ignoreGlobalRender && forceRender == false)
{
return;
}

var basic: Basic;
var i: number = 0;
Expand All @@ -128,9 +138,9 @@ module Phaser {
{
basic = this.members[i++];

if ((basic != null) && basic.exists && basic.visible)
if ((basic != null) && basic.exists && basic.visible && basic.ignoreGlobalRender == false)
{
basic.render(camera, cameraOffsetX, cameraOffsetY);
basic.render(camera, cameraOffsetX, cameraOffsetY, forceRender);
}
}
}
Expand Down Expand Up @@ -189,7 +199,7 @@ module Phaser {
* @param {Basic} Object The object you want to add to the group.
* @return {Basic} The same <code>Basic</code> object that was passed in.
*/
public add(Object: Basic) {
public add(Object: Basic): any {

//Don't bother adding an object twice.
if (this.members.indexOf(Object) >= 0)
Expand Down
11 changes: 9 additions & 2 deletions Phaser/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,32 @@ module Phaser {
* Local private reference to game.
*/
private _game: Game;

/**
* Array stors assets keys. So you can get that asset by its unique key.
*/
private _keys: string[];

/**
* Contains all the assets file infos.
*/
private _fileList;

/**
* Game initialial assets loading callback.
*/
private _gameCreateComplete;
private _onComplete;
private _onFileLoad;

/**
* Indicates assets loading progress. (from 0 to 100)
* @type {number}
*/
private _progressChunk: number;

private _xhr: XMLHttpRequest;

/**
* Length of assets queue.
* @type {number}
Expand All @@ -63,6 +69,7 @@ module Phaser {
* @type {boolean}
*/
public hasLoaded: bool;

/**
* Loading progress (from 0 to 1)
* @type {number}
Expand Down Expand Up @@ -404,9 +411,9 @@ module Phaser {

this.progress = Math.round(this.progress + this._progressChunk);

if (this.progress > 1)
if (this.progress > 100)
{
this.progress = 1;
this.progress = 100;
}

if (this._onFileLoad)
Expand Down
6 changes: 3 additions & 3 deletions Phaser/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ module Phaser {
/**
* Create a new object container.
*
* @param MaxSize {number} [optional] capacity of this group.
* @param maxSize {number} [optional] capacity of this group.
* @returns {Group} The newly created group.
*/
public createGroup(MaxSize?: number = 0): Group {
return this.game.world.createGroup(MaxSize);
public createGroup(maxSize?: number = 0): Group {
return this.game.world.createGroup(maxSize);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Phaser/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ module Phaser {
/**
* Create a new object container.
*
* @param [MaxSize] {number} capacity of this group.
* @param [maxSize] {number} capacity of this group.
* @returns {Group} The newly created group.
*/
public createGroup(MaxSize?: number = 0): Group {
return <Group> this.group.add(new Group(this._game, MaxSize));
public createGroup(maxSize?: number = 0): Group {
return <Group> this.group.add(new Group(this._game, maxSize));
}

/**
Expand Down
19 changes: 11 additions & 8 deletions Phaser/gameobjects/Emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ module Phaser {
* Creates a new <code>Emitter</code> object at a specific position.
* Does NOT automatically generate or attach particles!
*
* @param X {number} The X position of the emitter.
* @param Y {number} The Y position of the emitter.
* @param [Size] {number} specifies a maximum capacity for this emitter.
*/
constructor(game: Game, X: number = 0, Y: number = 0, Size: number = 0) {
super(game, Size);
this.x = X;
this.y = Y;
* @param x {number} The X position of the emitter.
* @param y {number} The Y position of the emitter.
* @param [size] {number} Specifies a maximum capacity for this emitter.
*/
constructor(game: Game, x: number = 0, y: number = 0, size: number = 0) {

super(game, size);

this.x = x;
this.y = y;
this.width = 0;
this.height = 0;
this.minParticleSpeed = new MicroPoint(-100, -100);
Expand All @@ -42,6 +44,7 @@ module Phaser {
this._explode = true;
this.on = false;
this._point = new MicroPoint();

}

/**
Expand Down
34 changes: 31 additions & 3 deletions Phaser/gameobjects/GameObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module Phaser {

super(game);

this.canvas = game.stage.canvas;
this.context = game.stage.context;

this.bounds = new Rectangle(x, y, width, height);
this.exists = true;
this.active = true;
Expand Down Expand Up @@ -126,7 +129,6 @@ module Phaser {
*/
public static ALIGN_BOTTOM_RIGHT: number = 8;


/**
* Enum value for outOfBoundsAction. Stop the object when is out of world bounds.
* @type {number}
Expand All @@ -139,12 +141,28 @@ module Phaser {
*/
public static OUT_OF_BOUNDS_KILL: number = 1;

/**
* A reference to the Canvas this GameObject will render to
* @type {HTMLCanvasElement}
*/
public canvas: HTMLCanvasElement;

/**
* A reference to the Canvas Context2D this GameObject will render to
* @type {CanvasRenderingContext2D}
*/
public context: CanvasRenderingContext2D;

/**
* Position of this object after scrolling.
* @type {MicroPoint}
*/
public _point: MicroPoint;

/**
* An Array of Cameras to which this GameObject won't render
* @type {Array}
*/
public cameraBlacklist: number[];

/**
Expand Down Expand Up @@ -352,8 +370,6 @@ module Phaser {
*/
public preUpdate() {

// flicker time

this.last.x = this.bounds.x;
this.last.y = this.bounds.y;

Expand Down Expand Up @@ -761,6 +777,18 @@ module Phaser {

}

/**
* Set the world bounds that this GameObject can exist within based on the size of the current game world.
*
* @param action {number} The action to take if the object hits the world bounds, either OUT_OF_BOUNDS_KILL or OUT_OF_BOUNDS_STOP
*/
public setBoundsFromWorld(action?: number = GameObject.OUT_OF_BOUNDS_STOP) {

this.setBounds(this._game.world.bounds.x, this._game.world.bounds.y, this._game.world.bounds.width, this._game.world.bounds.height);
this.outOfBoundsAction = action;

}

/**
* If you do not wish this object to be visible to a specific camera, pass the camera here.
*
Expand Down
Loading

0 comments on commit 5556859

Please sign in to comment.