Skip to content

Commit c5cccf3

Browse files
committed
Large refactoring of the pause and boot screens in Stage and various other small fixes
1 parent 9f23c37 commit c5cccf3

17 files changed

Lines changed: 12986 additions & 181 deletions

File tree

Docs/phaser_logo.png

809 Bytes
Loading

Phaser/Game.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ module Phaser {
9595
public device: Device;
9696

9797
public isBooted: bool = false;
98+
public isRunning: bool = false;
9899

99100
private boot(parent: string, width: number, height: number) {
100101

@@ -124,16 +125,16 @@ module Phaser {
124125
this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]);
125126

126127
this.framerate = 60;
128+
this.isBooted = true;
127129

128130
// Display the default game screen?
129131
if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
130132
{
131-
this.isBooted = false;
132-
this.stage.drawInitScreen();
133+
this._raf = new RequestAnimationFrame(this.bootLoop, this);
133134
}
134135
else
135136
{
136-
this.isBooted = true;
137+
this.isRunning = true;
137138
this._loadComplete = false;
138139

139140
this._raf = new RequestAnimationFrame(this.loop, this);
@@ -160,22 +161,33 @@ module Phaser {
160161

161162
}
162163

163-
private loop() {
164+
private bootLoop() {
164165

165166
this.time.update();
166167
this.tweens.update();
168+
this.input.update();
169+
this.stage.update();
167170

168-
if (this._paused == true)
169-
{
170-
if (this.onPausedCallback !== null)
171-
{
172-
this.onPausedCallback.call(this.callbackContext);
173-
}
171+
}
174172

175-
return;
173+
private pausedLoop() {
174+
175+
this.time.update();
176+
this.tweens.update();
177+
this.input.update();
178+
this.stage.update();
176179

180+
if (this.onPausedCallback !== null)
181+
{
182+
this.onPausedCallback.call(this.callbackContext);
177183
}
178184

185+
}
186+
187+
private loop() {
188+
189+
this.time.update();
190+
this.tweens.update();
179191
this.input.update();
180192
this.stage.update();
181193

@@ -349,12 +361,21 @@ module Phaser {
349361
if (value == true && this._paused == false)
350362
{
351363
this._paused = true;
364+
this._raf.setCallback(this.pausedLoop);
352365
}
353366
else if (value == false && this._paused == true)
354367
{
355368
this._paused = false;
356369
this.time.time = Date.now();
357370
this.input.reset();
371+
if (this.isRunning == false)
372+
{
373+
this._raf.setCallback(this.bootLoop);
374+
}
375+
else
376+
{
377+
this._raf.setCallback(this.loop);
378+
}
358379
}
359380

360381
}

Phaser/Phaser.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@
125125
<Content Include="SoundManager.js">
126126
<DependentUpon>SoundManager.ts</DependentUpon>
127127
</Content>
128+
<TypeScriptCompile Include="system\screens\PauseScreen.ts" />
129+
<TypeScriptCompile Include="system\screens\BootScreen.ts" />
130+
<Content Include="system\screens\BootScreen.js">
131+
<DependentUpon>BootScreen.ts</DependentUpon>
132+
</Content>
133+
<Content Include="system\screens\PauseScreen.js">
134+
<DependentUpon>PauseScreen.ts</DependentUpon>
135+
</Content>
128136
<Content Include="system\Sound.js">
129137
<DependentUpon>Sound.ts</DependentUpon>
130138
</Content>

Phaser/Phaser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Phaser
33
*
4-
* v0.9.4 - April 28th 2013
4+
* v0.9.5 - April 28th 2013
55
*
66
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
77
*
@@ -16,6 +16,6 @@
1616

1717
module Phaser {
1818

19-
export var VERSION: string = 'Phaser version 0.9.4';
19+
export var VERSION: string = 'Phaser version 0.9.5';
2020

2121
}

Phaser/Signal.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ module Phaser {
211211

212212
if (i !== -1)
213213
{
214-
this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal
214+
this._bindings[i]._destroy();
215215
this._bindings.splice(i, 1);
216216
}
217217

@@ -224,14 +224,17 @@ module Phaser {
224224
*/
225225
public removeAll() {
226226

227-
var n: number = this._bindings.length;
228-
229-
while (n--)
227+
if (this._bindings)
230228
{
231-
this._bindings[n]._destroy();
232-
}
229+
var n: number = this._bindings.length;
233230

234-
this._bindings.length = 0;
231+
while (n--)
232+
{
233+
this._bindings[n]._destroy();
234+
}
235+
236+
this._bindings.length = 0;
237+
}
235238

236239
}
237240

Phaser/Stage.ts

Lines changed: 31 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/// <reference path="Phaser.ts" />
22
/// <reference path="Game.ts" />
33
/// <reference path="system/StageScaleMode.ts" />
4+
/// <reference path="system/screens/BootScreen.ts" />
5+
/// <reference path="system/screens/PauseScreen.ts" />
46

57
/**
68
* Phaser - Stage
@@ -43,6 +45,9 @@ module Phaser {
4345
this.scaleMode = StageScaleMode.NO_SCALE;
4446
this.scale = new StageScaleMode(this._game);
4547

48+
this._bootScreen = new BootScreen(this._game);
49+
this._pauseScreen = new PauseScreen(this._game, width, height);
50+
4651
document.addEventListener('visibilitychange', (event) => this.visibilityChange(event), false);
4752
document.addEventListener('webkitvisibilitychange', (event) => this.visibilityChange(event), false);
4853
window.onblur = (event) => this.visibilityChange(event);
@@ -52,7 +57,8 @@ module Phaser {
5257

5358
private _game: Game;
5459
private _bgColor: string;
55-
60+
private _bootScreen;
61+
private _pauseScreen;
5662

5763
public static ORIENTATION_LANDSCAPE: number = 0;
5864
public static ORIENTATION_PORTRAIT: number = 1;
@@ -63,6 +69,7 @@ module Phaser {
6369
public canvas: HTMLCanvasElement;
6470
public context: CanvasRenderingContext2D;
6571
public disablePauseScreen: bool = false;
72+
public disableBootScreen: bool = false;
6673
public offset: Point;
6774
public scale: StageScaleMode;
6875
public scaleMode: number;
@@ -82,91 +89,48 @@ module Phaser {
8289
this.context.clearRect(0, 0, this.width, this.height);
8390
}
8491

85-
}
86-
87-
public renderDebugInfo() {
92+
if (this._game.isRunning == false && this.disableBootScreen == false)
93+
{
94+
this._bootScreen.update();
95+
this._bootScreen.render();
96+
}
8897

89-
this.context.fillStyle = 'rgb(255,255,255)';
90-
this.context.fillText(Phaser.VERSION, 10, 20);
91-
this.context.fillText('Game Size: ' + this.width + ' x ' + this.height, 10, 40);
92-
this.context.fillText('x: ' + this.x + ' y: ' + this.y, 10, 60);
98+
if (this._game.paused == true && this.disablePauseScreen == false)
99+
{
100+
this._pauseScreen.update();
101+
this._pauseScreen.render();
102+
}
93103

94104
}
95105

96-
//if (document['hidden'] === true || document['webkitHidden'] === true)
97106
private visibilityChange(event) {
98107

99-
//console.log(event);
100-
101108
if (this.disablePauseScreen)
102109
{
103110
return;
104111
}
105112

106-
if (event.type == 'blur' && this._game.paused == false && this._game.isBooted == true)
113+
if (event.type === 'blur' || document['hidden'] === true || document['webkitHidden'] === true)
107114
{
108-
this._game.paused = true;
109-
this.drawPauseScreen();
115+
if (this._game.paused == false)
116+
{
117+
this._pauseScreen.onPaused();
118+
this.saveCanvasValues();
119+
this._game.paused = true;
120+
}
110121
}
111122
else if (event.type == 'focus')
112123
{
113-
this._game.paused = false;
124+
if (this._game.paused == true)
125+
{
126+
this._pauseScreen.onResume();
127+
this._game.paused = false;
128+
this.restoreCanvasValues();
129+
}
114130
}
115131

116132
}
117133

118-
public drawInitScreen() {
119-
120-
this.context.fillStyle = 'rgb(40, 40, 40)';
121-
this.context.fillRect(0, 0, this.width, this.height);
122-
123-
this.context.fillStyle = 'rgb(255,255,255)';
124-
this.context.font = 'bold 18px Arial';
125-
this.context.textBaseline = 'top';
126-
this.context.fillText(Phaser.VERSION, 54, 32);
127-
this.context.fillText('Game Size: ' + this.width + ' x ' + this.height, 32, 64);
128-
this.context.fillText('www.photonstorm.com', 32, 96);
129-
this.context.font = '16px Arial';
130-
this.context.fillText('You are seeing this screen because you didn\'t specify any default', 32, 160);
131-
this.context.fillText('functions in the Game constructor, or use Game.loadState()', 32, 184);
132-
133-
var image = new Image();
134-
var that = this;
135-
136-
image.onload = function () {
137-
that.context.drawImage(image, 32, 32);
138-
};
139-
140-
image.src = this._logo;
141-
142-
}
143-
144-
private drawPauseScreen() {
145-
146-
this.saveCanvasValues();
147-
148-
this.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
149-
this.context.fillRect(0, 0, this.width, this.height);
150-
151-
// Draw a 'play' arrow
152-
var arrowWidth = Math.round(this.width / 2);
153-
var arrowHeight = Math.round(this.height / 2);
154-
155-
var sx = this.centerX - arrowWidth / 2;
156-
var sy = this.centerY - arrowHeight / 2;
157-
158-
this.context.beginPath();
159-
this.context.moveTo(sx, sy);
160-
this.context.lineTo(sx, sy + arrowHeight);
161-
this.context.lineTo(sx + arrowWidth, this.centerY);
162-
this.context.fillStyle = 'rgba(255, 255, 255, 0.8)';
163-
this.context.fill();
164-
this.context.closePath();
165-
166-
this.restoreCanvasValues();
167-
168-
}
169-
170134
private getOffset(element): Point {
171135

172136
var box = element.getBoundingClientRect();
@@ -240,8 +204,6 @@ module Phaser {
240204
return Math.round(Math.random() * this.bounds.height);
241205
}
242206

243-
private _logo: string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNpi/P//PwM6YGRkxBQEAqBaRnQxFmwa10d6MAjrMqMofHv5L1we2SBGmAtAktg0ogOQQYHLd8ANYYFpPtTmzUAMAFmwnsEDrAdkCAvMZlIAsiFMMAEYsKvaSrQhIMCELkGsV2AAbIC8gCQYgwKIUABiNYBf9yoYH7n7n6CzN274g2IYEyFbsNmKLIaSkHpP7WSwUfbA0ASzFQRslBlxp0RcAF0TRhggA3zhAJIDpUKU5A9KyshpHDkjFZu5g2nJMFcwXVJSgqIGnBKx5bKenh4w/XzVbgbPtlIUcVgSxuoCUgHIIIAAAwArtXwJBABO6QAAAABJRU5ErkJggg==";
244-
245207
}
246208

247209
}

Phaser/gameobjects/GameObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ module Phaser {
323323
* Checks to see if a point in 2D world space overlaps this <code>GameObject</code>.
324324
*
325325
* @param Point The point in world space you want to check.
326-
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap.
326+
* @param InScreenSpace Whether to take scroll factors into account when checking for overlap.
327327
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
328328
*
329329
* @return Whether or not the point overlaps this object.

Phaser/phaser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Phaser
33
*
4-
* v0.9.4 - April 28th 2013
4+
* v0.9.5 - April 28th 2013
55
*
66
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
77
*
@@ -15,5 +15,5 @@
1515
*/
1616
var Phaser;
1717
(function (Phaser) {
18-
Phaser.VERSION = 'Phaser version 0.9.4';
18+
Phaser.VERSION = 'Phaser version 0.9.5';
1919
})(Phaser || (Phaser = {}));

Phaser/system/Tween.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Phaser {
3030
this._interpolationFunction = this._game.math.linearInterpolation;
3131
this._easingFunction = Phaser.Easing.Linear.None;
3232

33+
this._chainedTweens = [];
3334
this.onStart = new Phaser.Signal();
3435
this.onUpdate = new Phaser.Signal();
3536
this.onComplete = new Phaser.Signal();
@@ -126,6 +127,8 @@ module Phaser {
126127
this._manager.remove(this);
127128
}
128129

130+
this.onComplete.dispose();
131+
129132
return this;
130133

131134
}

0 commit comments

Comments
 (0)