Skip to content

Commit 49fe5ee

Browse files
committed
Added Group IDs and references to Sprites, Group sorting, z-index values and child swapping. Also added all of the drag and bounds methods to Input.
1 parent 59f7a59 commit 49fe5ee

22 files changed

Lines changed: 1891 additions & 237 deletions

Phaser/Game.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,12 @@ module Phaser {
295295

296296
this.setRenderer(Phaser.Types.RENDERER_CANVAS);
297297

298+
this.world.boot();
299+
this.stage.boot();
300+
this.input.boot();
301+
298302
this.framerate = 60;
299303
this.isBooted = true;
300-
this.input.start();
301304

302305
// Display the default game screen?
303306
if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
@@ -354,7 +357,7 @@ module Phaser {
354357
}
355358

356359
/**
357-
* Game loop method will be called when it's booting.
360+
* The bootLoop is called while the game is still booting (waiting for the DOM and resources to be available)
358361
*/
359362
private bootLoop() {
360363

@@ -365,7 +368,7 @@ module Phaser {
365368
}
366369

367370
/**
368-
* Game loop method will be called when it's paused.
371+
* The pausedLoop is called when the game is paused.
369372
*/
370373
private pausedLoop() {
371374

@@ -563,7 +566,7 @@ module Phaser {
563566
}
564567

565568
/**
566-
* Nuke the whole game from orbit
569+
* Nuke the entire game from orbit
567570
*/
568571
public destroy() {
569572

Phaser/Stage.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ module Phaser {
5757
this.scaleMode = StageScaleMode.NO_SCALE;
5858
this.scale = new StageScaleMode(this._game);
5959

60-
this._bootScreen = new BootScreen(this._game);
61-
this._pauseScreen = new PauseScreen(this._game, width, height);
62-
6360
document.addEventListener('visibilitychange', (event) => this.visibilityChange(event), false);
6461
document.addEventListener('webkitvisibilitychange', (event) => this.visibilityChange(event), false);
6562
window.onblur = (event) => this.visibilityChange(event);
@@ -153,6 +150,16 @@ module Phaser {
153150
*/
154151
public scaleMode: number;
155152

153+
/**
154+
* Stage boot
155+
*/
156+
public boot() {
157+
158+
this._bootScreen = new BootScreen(this._game);
159+
this._pauseScreen = new PauseScreen(this._game, this.width, this.height);
160+
161+
}
162+
156163
/**
157164
* Update stage for rendering. This will handle scaling, clearing
158165
* and PauseScreen/BootScreen updating and rendering.

Phaser/State.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ module Phaser {
2121
this.add = game.add;
2222
this.camera = game.camera;
2323
this.cache = game.cache;
24-
//this.collision = game.collision;
2524
this.input = game.input;
2625
this.loader = game.loader;
2726
this.math = game.math;
28-
//this.motion = game.motion;
27+
this.motion = game.motion;
2928
this.sound = game.sound;
3029
this.stage = game.stage;
3130
this.time = game.time;
@@ -51,12 +50,6 @@ module Phaser {
5150
*/
5251
public cache: Cache;
5352

54-
/**
55-
* Reference to the collision helper.
56-
* @type {Collision}
57-
*/
58-
//public collision: Collision;
59-
6053
/**
6154
* Reference to the GameObject Factory.
6255
* @type {GameObjectFactory}
@@ -85,7 +78,7 @@ module Phaser {
8578
* Reference to the motion helper.
8679
* @type {Motion}
8780
*/
88-
//public motion: Motion;
81+
public motion: Motion;
8982

9083
/**
9184
* Reference to the sound manager.

Phaser/World.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ module Phaser {
3131

3232
this.cameras = new CameraManager(this._game, 0, 0, width, height);
3333

34-
this.group = new Group(this._game, 0);
35-
3634
this.bounds = new Rectangle(0, 0, width, height);
3735

38-
this.physics = new Physics.PhysicsManager(this._game, width, height);
39-
4036
}
4137

4238
/**
@@ -68,6 +64,26 @@ module Phaser {
6864
*/
6965
public physics: Physics.PhysicsManager;
7066

67+
/**
68+
* Object container stores every object created with `create*` methods.
69+
* @type {Group}
70+
*/
71+
private _groupCounter: number = 0;
72+
73+
public getNextGroupID(): number {
74+
return this._groupCounter++;
75+
}
76+
77+
/**
78+
* Called one by Game during the boot process.
79+
*/
80+
public boot() {
81+
82+
this.group = new Group(this._game, 0);
83+
84+
this.physics = new Physics.PhysicsManager(this._game, this.width, this.height);
85+
86+
}
7187

7288
/**
7389
* This is called automatically every frame, and is where main logic happens.

Phaser/components/sprite/Events.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ module Phaser.Components {
1919
this.game = parent.game;
2020
this._sprite = parent;
2121

22+
this.onAddedToGroup = new Phaser.Signal;
23+
this.onRemovedFromGroup = new Phaser.Signal;
24+
this.onKilled = new Phaser.Signal;
25+
this.onRevived = new Phaser.Signal;
26+
2227
this.onInputOver = new Phaser.Signal;
2328
this.onInputOut = new Phaser.Signal;
2429
this.onInputDown = new Phaser.Signal;
@@ -36,14 +41,25 @@ module Phaser.Components {
3641
*/
3742
private _sprite: Sprite;
3843

39-
// Creation and destruction
40-
public onAdded: Phaser.Signal;
41-
public onKilled: Phaser.Signal;
42-
public onRevived: Phaser.Signal;
44+
/**
45+
* Dispatched by the Group this Sprite is added to.
46+
*/
47+
public onAddedToGroup: Phaser.Signal;
4348

44-
public onOutOfBounds: Phaser.Signal;
49+
/**
50+
* Dispatched by the Group this Sprite is removed from.
51+
*/
52+
public onRemovedFromGroup: Phaser.Signal;
53+
54+
/**
55+
* Dispatched when this Sprite is killed.
56+
*/
57+
public onKilled: Phaser.Signal;
4558

46-
// Input related events
59+
/**
60+
* Dispatched when this Sprite is revived.
61+
*/
62+
public onRevived: Phaser.Signal;
4763

4864
/**
4965
* Dispatched by the Input component when a pointer moves over an Input enabled sprite.
@@ -65,6 +81,11 @@ module Phaser.Components {
6581
*/
6682
public onInputUp: Phaser.Signal;
6783

84+
85+
86+
87+
public onOutOfBounds: Phaser.Signal;
88+
6889
}
6990

7091
}

0 commit comments

Comments
 (0)