Skip to content

Commit 5556859

Browse files
committed
Lots of updates across input, rendering and grouping
1 parent a6e8436 commit 5556859

40 files changed

Lines changed: 840 additions & 479 deletions

Phaser/AnimationManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Phaser {
3434
* Local private reference to game.
3535
*/
3636
private _game: Game;
37+
3738
/**
3839
* Local private reference to its owner sprite.
3940
*/
@@ -43,11 +44,13 @@ module Phaser {
4344
* Animation key-value container.
4445
*/
4546
private _anims: {};
47+
4648
/**
4749
* Index of current frame.
4850
* @type {number}
4951
*/
5052
private _frameIndex: number;
53+
5154
/**
5255
* Data contains animation frames.
5356
* @type {FrameData}
@@ -58,6 +61,7 @@ module Phaser {
5861
* Keeps track of the current animation being played.
5962
*/
6063
public currentAnim: Animation;
64+
6165
/**
6266
* Keeps track of the current frame of animation.
6367
*/

Phaser/Basic.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module Phaser {
2323
this.visible = true;
2424
this.alive = true;
2525
this.isGroup = false;
26+
this.ignoreGlobalUpdate = false;
27+
this.ignoreGlobalRender = false;
2628
this.ignoreDrawDebug = false;
2729

2830
}
@@ -70,6 +72,16 @@ module Phaser {
7072
*/
7173
public alive: bool;
7274

75+
/**
76+
* 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)
77+
*/
78+
public ignoreGlobalUpdate: bool;
79+
80+
/**
81+
* 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)
82+
*/
83+
public ignoreGlobalRender: bool;
84+
7385
/**
7486
* Setting this to true will prevent the object from appearing
7587
* when the visual debug mode in the debugger overlay is toggled on.
@@ -93,7 +105,7 @@ module Phaser {
93105
* Override this to update your class's position and appearance.
94106
* This is where most of your game rules and behavioral code will go.
95107
*/
96-
public update() {
108+
public update(forceUpdate?: bool = false) {
97109
}
98110

99111
/**
@@ -102,7 +114,7 @@ module Phaser {
102114
public postUpdate() {
103115
}
104116

105-
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
117+
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number, forceRender?: bool = false) {
106118
}
107119

108120
/**

Phaser/DynamicTexture.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ module Phaser {
239239

240240
}
241241

242+
/**
243+
* Given an array of GameObjects it will update each of them so that their canvas/contexts reference this DynamicTexture
244+
* @param objects {Array} An array of GameObjects, or objects that inherit from it such as Sprites
245+
*/
246+
public assignCanvasToGameObjects(objects: GameObject[]) {
247+
248+
for (var i = 0; i < objects.length; i++)
249+
{
250+
objects[i].canvas = this.canvas;
251+
objects[i].context = this.context;
252+
}
253+
254+
}
255+
242256
/**
243257
* Clear the whole canvas.
244258
*/
@@ -248,6 +262,18 @@ module Phaser {
248262

249263
}
250264

265+
/**
266+
* Renders this DynamicTexture to the Stage at the given x/y coordinates
267+
*
268+
* @param x {number} The X coordinate to render on the stage to (given in screen coordinates, not world)
269+
* @param y {number} The Y coordinate to render on the stage to (given in screen coordinates, not world)
270+
*/
271+
public render(x?: number = 0, y?: number = 0) {
272+
273+
this._game.stage.context.drawImage(this.canvas, x, y);
274+
275+
}
276+
251277
public get width(): number {
252278
return this.bounds.width;
253279
}

Phaser/Game.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,11 @@ module Phaser {
661661
/**
662662
* Create a new object container.
663663
*
664-
* @param MaxSize {number} Optional, capacity of this group.
664+
* @param maxSize {number} Optional, capacity of this group.
665665
* @returns {Group} The newly created group.
666666
*/
667-
public createGroup(MaxSize?: number = 0): Group {
668-
return this.world.createGroup(MaxSize);
667+
public createGroup(maxSize?: number = 0): Group {
668+
return this.world.createGroup(maxSize);
669669
}
670670

671671
/**

Phaser/Group.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ module Phaser {
9898
/**
9999
* Automatically goes through and calls update on everything you added.
100100
*/
101-
public update() {
101+
public update(forceUpdate?: bool = false) {
102+
103+
if (this.ignoreGlobalUpdate && forceUpdate == false)
104+
{
105+
return;
106+
}
102107

103108
var basic: Basic;
104109
var i: number = 0;
@@ -107,10 +112,10 @@ module Phaser {
107112
{
108113
basic = this.members[i++];
109114

110-
if ((basic != null) && basic.exists && basic.active)
115+
if ((basic != null) && basic.exists && basic.active && basic.ignoreGlobalUpdate == false)
111116
{
112117
basic.preUpdate();
113-
basic.update();
118+
basic.update(forceUpdate);
114119
basic.postUpdate();
115120
}
116121
}
@@ -119,7 +124,12 @@ module Phaser {
119124
/**
120125
* Automatically goes through and calls render on everything you added.
121126
*/
122-
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
127+
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number, forceRender?: bool = false) {
128+
129+
if (this.ignoreGlobalRender && forceRender == false)
130+
{
131+
return;
132+
}
123133

124134
var basic: Basic;
125135
var i: number = 0;
@@ -128,9 +138,9 @@ module Phaser {
128138
{
129139
basic = this.members[i++];
130140

131-
if ((basic != null) && basic.exists && basic.visible)
141+
if ((basic != null) && basic.exists && basic.visible && basic.ignoreGlobalRender == false)
132142
{
133-
basic.render(camera, cameraOffsetX, cameraOffsetY);
143+
basic.render(camera, cameraOffsetX, cameraOffsetY, forceRender);
134144
}
135145
}
136146
}
@@ -189,7 +199,7 @@ module Phaser {
189199
* @param {Basic} Object The object you want to add to the group.
190200
* @return {Basic} The same <code>Basic</code> object that was passed in.
191201
*/
192-
public add(Object: Basic) {
202+
public add(Object: Basic): any {
193203

194204
//Don't bother adding an object twice.
195205
if (this.members.indexOf(Object) >= 0)

Phaser/Loader.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,32 @@ module Phaser {
3232
* Local private reference to game.
3333
*/
3434
private _game: Game;
35+
3536
/**
3637
* Array stors assets keys. So you can get that asset by its unique key.
3738
*/
3839
private _keys: string[];
40+
3941
/**
4042
* Contains all the assets file infos.
4143
*/
4244
private _fileList;
45+
4346
/**
4447
* Game initialial assets loading callback.
4548
*/
4649
private _gameCreateComplete;
4750
private _onComplete;
4851
private _onFileLoad;
52+
4953
/**
5054
* Indicates assets loading progress. (from 0 to 100)
5155
* @type {number}
5256
*/
5357
private _progressChunk: number;
58+
5459
private _xhr: XMLHttpRequest;
60+
5561
/**
5662
* Length of assets queue.
5763
* @type {number}
@@ -63,6 +69,7 @@ module Phaser {
6369
* @type {boolean}
6470
*/
6571
public hasLoaded: bool;
72+
6673
/**
6774
* Loading progress (from 0 to 1)
6875
* @type {number}
@@ -404,9 +411,9 @@ module Phaser {
404411

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

407-
if (this.progress > 1)
414+
if (this.progress > 100)
408415
{
409-
this.progress = 1;
416+
this.progress = 100;
410417
}
411418

412419
if (this._onFileLoad)

Phaser/State.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ module Phaser {
196196
/**
197197
* Create a new object container.
198198
*
199-
* @param MaxSize {number} [optional] capacity of this group.
199+
* @param maxSize {number} [optional] capacity of this group.
200200
* @returns {Group} The newly created group.
201201
*/
202-
public createGroup(MaxSize?: number = 0): Group {
203-
return this.game.world.createGroup(MaxSize);
202+
public createGroup(maxSize?: number = 0): Group {
203+
return this.game.world.createGroup(maxSize);
204204
}
205205

206206
/**

Phaser/World.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ module Phaser {
222222
/**
223223
* Create a new object container.
224224
*
225-
* @param [MaxSize] {number} capacity of this group.
225+
* @param [maxSize] {number} capacity of this group.
226226
* @returns {Group} The newly created group.
227227
*/
228-
public createGroup(MaxSize?: number = 0): Group {
229-
return <Group> this.group.add(new Group(this._game, MaxSize));
228+
public createGroup(maxSize?: number = 0): Group {
229+
return <Group> this.group.add(new Group(this._game, maxSize));
230230
}
231231

232232
/**

Phaser/gameobjects/Emitter.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ module Phaser {
1717
* Creates a new <code>Emitter</code> object at a specific position.
1818
* Does NOT automatically generate or attach particles!
1919
*
20-
* @param X {number} The X position of the emitter.
21-
* @param Y {number} The Y position of the emitter.
22-
* @param [Size] {number} specifies a maximum capacity for this emitter.
23-
*/
24-
constructor(game: Game, X: number = 0, Y: number = 0, Size: number = 0) {
25-
super(game, Size);
26-
this.x = X;
27-
this.y = Y;
20+
* @param x {number} The X position of the emitter.
21+
* @param y {number} The Y position of the emitter.
22+
* @param [size] {number} Specifies a maximum capacity for this emitter.
23+
*/
24+
constructor(game: Game, x: number = 0, y: number = 0, size: number = 0) {
25+
26+
super(game, size);
27+
28+
this.x = x;
29+
this.y = y;
2830
this.width = 0;
2931
this.height = 0;
3032
this.minParticleSpeed = new MicroPoint(-100, -100);
@@ -42,6 +44,7 @@ module Phaser {
4244
this._explode = true;
4345
this.on = false;
4446
this._point = new MicroPoint();
47+
4548
}
4649

4750
/**

Phaser/gameobjects/GameObject.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ module Phaser {
2727

2828
super(game);
2929

30+
this.canvas = game.stage.canvas;
31+
this.context = game.stage.context;
32+
3033
this.bounds = new Rectangle(x, y, width, height);
3134
this.exists = true;
3235
this.active = true;
@@ -126,7 +129,6 @@ module Phaser {
126129
*/
127130
public static ALIGN_BOTTOM_RIGHT: number = 8;
128131

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

144+
/**
145+
* A reference to the Canvas this GameObject will render to
146+
* @type {HTMLCanvasElement}
147+
*/
148+
public canvas: HTMLCanvasElement;
149+
150+
/**
151+
* A reference to the Canvas Context2D this GameObject will render to
152+
* @type {CanvasRenderingContext2D}
153+
*/
154+
public context: CanvasRenderingContext2D;
155+
142156
/**
143157
* Position of this object after scrolling.
144158
* @type {MicroPoint}
145159
*/
146160
public _point: MicroPoint;
147161

162+
/**
163+
* An Array of Cameras to which this GameObject won't render
164+
* @type {Array}
165+
*/
148166
public cameraBlacklist: number[];
149167

150168
/**
@@ -352,8 +370,6 @@ module Phaser {
352370
*/
353371
public preUpdate() {
354372

355-
// flicker time
356-
357373
this.last.x = this.bounds.x;
358374
this.last.y = this.bounds.y;
359375

@@ -761,6 +777,18 @@ module Phaser {
761777

762778
}
763779

780+
/**
781+
* Set the world bounds that this GameObject can exist within based on the size of the current game world.
782+
*
783+
* @param action {number} The action to take if the object hits the world bounds, either OUT_OF_BOUNDS_KILL or OUT_OF_BOUNDS_STOP
784+
*/
785+
public setBoundsFromWorld(action?: number = GameObject.OUT_OF_BOUNDS_STOP) {
786+
787+
this.setBounds(this._game.world.bounds.x, this._game.world.bounds.y, this._game.world.bounds.width, this._game.world.bounds.height);
788+
this.outOfBoundsAction = action;
789+
790+
}
791+
764792
/**
765793
* If you do not wish this object to be visible to a specific camera, pass the camera here.
766794
*

0 commit comments

Comments
 (0)