Skip to content

Commit 727a06c

Browse files
committed
Merge branch 'photonstorm/097'
2 parents 9f30f65 + a2c756e commit 727a06c

258 files changed

Lines changed: 23270 additions & 654 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Phaser/Game.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/// <reference path="cameras/CameraManager.ts" />
1515
/// <reference path="gameobjects/GameObjectFactory.ts" />
1616
/// <reference path="sound/SoundManager.ts" />
17+
/// <reference path="sound/Sound.ts" />
1718
/// <reference path="Stage.ts" />
1819
/// <reference path="Time.ts" />
1920
/// <reference path="tweens/TweenManager.ts" />
@@ -298,12 +299,12 @@ module Phaser {
298299
this.stage = new Stage(this, parent, width, height);
299300
this.world = new World(this, width, height);
300301
this.add = new GameObjectFactory(this);
301-
this.sound = new SoundManager(this);
302302
this.cache = new Cache(this);
303303
this.load = new Loader(this, this.loadComplete);
304304
this.time = new Time(this);
305305
this.tweens = new TweenManager(this);
306306
this.input = new Input(this);
307+
this.sound = new SoundManager(this);
307308
this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]);
308309
this.physics = new Physics.Manager(this);
309310

@@ -391,6 +392,7 @@ module Phaser {
391392
this.tweens.update();
392393
this.input.update();
393394
this.stage.update();
395+
this.sound.update();
394396

395397
if (this.onPausedCallback !== null)
396398
{
@@ -407,6 +409,7 @@ module Phaser {
407409
this.tweens.update();
408410
this.input.update();
409411
this.stage.update();
412+
this.sound.update();
410413
this.physics.update();
411414
this.world.update();
412415

@@ -636,13 +639,15 @@ module Phaser {
636639
if (value == true && this._paused == false)
637640
{
638641
this._paused = true;
642+
this.sound.pauseAll();
639643
this._raf.callback = this.pausedLoop;
640644
}
641645
else if (value == false && this._paused == true)
642646
{
643647
this._paused = false;
644648
//this.time.time = window.performance.now ? (performance.now() + performance.timing.navigationStart) : Date.now();
645649
this.input.reset();
650+
this.sound.resumeAll();
646651

647652
if (this.isRunning == false)
648653
{

Phaser/Stage.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ module Phaser {
6161

6262
document.addEventListener('visibilitychange', (event) => this.visibilityChange(event), false);
6363
document.addEventListener('webkitvisibilitychange', (event) => this.visibilityChange(event), false);
64+
document.addEventListener('pagehide', (event) => this.visibilityChange(event), false);
65+
document.addEventListener('pageshow', (event) => this.visibilityChange(event), false);
6466
window.onblur = (event) => this.visibilityChange(event);
6567
window.onfocus = (event) => this.visibilityChange(event);
6668

@@ -211,24 +213,27 @@ module Phaser {
211213
*/
212214
private visibilityChange(event) {
213215

214-
if (this.disablePauseScreen)
216+
if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true)
215217
{
216-
return;
217-
}
218-
219-
if (event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true)
220-
{
221-
if (this._game.paused == false)
218+
if (this._game.paused == false && this.disablePauseScreen == false)
222219
{
223220
this.pauseGame();
224221
}
222+
else
223+
{
224+
this._game.paused = true;
225+
}
225226
}
226227
else
227228
{
228-
if (this._game.paused == true)
229+
if (this._game.paused == true && this.disablePauseScreen == false)
229230
{
230231
this.resumeGame();
231232
}
233+
else
234+
{
235+
this._game.paused = false;
236+
}
232237
}
233238

234239
}

Phaser/Statics.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ module Phaser {
3030
static BODY_KINETIC: number = 2;
3131
static BODY_DYNAMIC: number = 3;
3232

33+
static OUT_OF_BOUNDS_KILL: number = 0;
34+
static OUT_OF_BOUNDS_DESTROY: number = 1;
35+
static OUT_OF_BOUNDS_PERSIST: number = 2;
36+
3337
/**
3438
* Flag used to allow GameObjects to collide on their left side
3539
* @type {number}

Phaser/components/sprite/Events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module Phaser.Components.Sprite {
2323
this.onRemovedFromGroup = new Phaser.Signal;
2424
this.onKilled = new Phaser.Signal;
2525
this.onRevived = new Phaser.Signal;
26+
this.onOutOfBounds = new Phaser.Signal;
2627

2728
}
2829

@@ -101,6 +102,9 @@ module Phaser.Components.Sprite {
101102
*/
102103
public onAnimationLoop: Phaser.Signal;
103104

105+
/**
106+
* Dispatched by the Sprite when it first leaves the world bounds
107+
*/
104108
public onOutOfBounds: Phaser.Signal;
105109

106110
}

Phaser/gameobjects/Button.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ module Phaser {
1919
* Create a new <code>Button</code> object.
2020
*
2121
* @param game {Phaser.Game} Current game instance.
22-
* @param [x] {number} the initial x position of the button.
23-
* @param [y] {number} the initial y position of the button.
24-
* @param [key] {string} Key of the graphic you want to load for this button.
22+
* @param [x] {number} X position of the button.
23+
* @param [y] {number} Y position of the button.
24+
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this button.
25+
* @param [callback] {function} The function to call when this button is pressed
26+
* @param [callbackContext] {object} The context in which the callback will be called (usually 'this')
27+
* @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
28+
* @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
29+
* @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
2530
*/
2631
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, callback? = null, callbackContext? = null, overFrame? = null, outFrame? = null, downFrame? = null) {
2732

Phaser/gameobjects/GameObjectFactory.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ module Phaser {
9494
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, bodyType));
9595
}
9696

97+
public audio(key: string, volume?: number = 1, loop?: bool = false) {
98+
return <Sound> this._game.sound.add(key, volume, loop);
99+
}
100+
97101
/**
98102
* Create a new Sprite with the physics automatically created and set to DYNAMIC. The Sprite position offset is set to its center.
99103
*
@@ -182,13 +186,14 @@ module Phaser {
182186
}
183187

184188
/**
185-
* Create a tween object for a specific object.
189+
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
186190
*
187-
* @param obj Object you wish the tween will affect.
191+
* @param obj {object} Object the tween will be run on.
192+
* @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
188193
* @return {Phaser.Tween} The newly created tween object.
189194
*/
190-
public tween(obj): Tween {
191-
return this._game.tweens.create(obj);
195+
public tween(obj, localReference?:bool = false): Tween {
196+
return this._game.tweens.create(obj, localReference);
192197
}
193198

194199
/**
@@ -202,6 +207,17 @@ module Phaser {
202207
return this._world.group.add(sprite);
203208
}
204209

210+
/**
211+
* Add an existing Button to the current world.
212+
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
213+
*
214+
* @param button The Button to add to the Game World
215+
* @return {Phaser.Button} The Button object
216+
*/
217+
public existingButton(button: Button): Button {
218+
return this._world.group.add(button);
219+
}
220+
205221
/**
206222
* Add an existing GeomSprite to the current world.
207223
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.

Phaser/gameobjects/Sprite.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ module Phaser {
8181

8282
this.transform.setCache();
8383

84+
this.outOfBounds = false;
85+
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
86+
8487
// Handy proxies
8588
this.scale = this.transform.scale;
8689
this.alpha = this.texture.alpha;
@@ -128,6 +131,17 @@ module Phaser {
128131
*/
129132
public alive: bool;
130133

134+
/**
135+
* Is the Sprite out of the world bounds or not?
136+
*/
137+
public outOfBounds: bool;
138+
139+
/**
140+
* The action to be taken when the sprite is fully out of the world bounds
141+
* Defaults to Phaser.Types.OUT_OF_BOUNDS_KILL
142+
*/
143+
public outOfBoundsAction: number;
144+
131145
/**
132146
* Sprite physics body.
133147
*/
@@ -171,6 +185,11 @@ module Phaser {
171185
*/
172186
public cameraView: Phaser.Rectangle;
173187

188+
/**
189+
* A local tween variable. Used by the TweenManager when setting a tween on this sprite or a property of it.
190+
*/
191+
public tween: Phaser.Tween;
192+
174193
/**
175194
* A boolean representing if the Sprite has been modified in any way via a scale, rotate, flip or skew.
176195
*/
@@ -314,44 +333,34 @@ module Phaser {
314333
}
315334

316335
/**
317-
* Automatically called after update() by the game loop.
336+
* Automatically called after update() by the game loop for all 'alive' objects.
318337
*/
319338
public postUpdate() {
320339

321340
this.animations.update();
322341

323-
/*
324-
if (this.worldBounds != null)
342+
if (Phaser.RectangleUtils.intersects(this.worldView, this.game.world.bounds))
325343
{
326-
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
344+
this.outOfBounds = false;
345+
}
346+
else
347+
{
348+
if (this.outOfBounds == false)
327349
{
328-
if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom)
329-
{
330-
this.kill();
331-
}
350+
this.events.onOutOfBounds.dispatch(this);
332351
}
333-
else
352+
353+
this.outOfBounds = true;
354+
355+
if (this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_KILL)
356+
{
357+
this.kill();
358+
}
359+
else if (this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_DESTROY)
334360
{
335-
if (this.x < this.worldBounds.x)
336-
{
337-
this.x = this.worldBounds.x;
338-
}
339-
else if (this.x > this.worldBounds.right)
340-
{
341-
this.x = this.worldBounds.right;
342-
}
343-
344-
if (this.y < this.worldBounds.y)
345-
{
346-
this.y = this.worldBounds.y;
347-
}
348-
else if (this.y > this.worldBounds.bottom)
349-
{
350-
this.y = this.worldBounds.bottom;
351-
}
361+
this.destroy();
352362
}
353363
}
354-
*/
355364

356365
if (this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
357366
{

Phaser/input/Input.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ module Phaser {
275275
* @property recordPointerHistory
276276
* @type {Boolean}
277277
**/
278-
public recordPointerHistory: bool = true;
278+
public recordPointerHistory: bool = false;
279279

280280
/**
281281
* The rate in milliseconds at which the Pointer objects should update their tracking history
@@ -286,7 +286,7 @@ module Phaser {
286286

287287
/**
288288
* The total number of entries that can be recorded into the Pointer objects tracking history.
289-
* The the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history.
289+
* If the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history.
290290
* @property recordLimit
291291
* @type {Number}
292292
*/

Phaser/input/Pointer.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ module Phaser {
3333

3434
}
3535

36+
private _highestRenderOrderID: number;
37+
private _highestRenderObject: number;
38+
private _highestInputPriorityID: number;
39+
3640
/**
3741
* Local private reference to game.
3842
* @property game
@@ -239,6 +243,13 @@ module Phaser {
239243
**/
240244
public totalTouches: number = 0;
241245

246+
/**
247+
* The number of miliseconds since the last click
248+
* @property msSinceLastClick
249+
* @type {Number}
250+
**/
251+
public msSinceLastClick: number = Number.MAX_VALUE;
252+
242253
/**
243254
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
244255
* @property duration
@@ -306,7 +317,12 @@ module Phaser {
306317
this.withinGame = true;
307318
this.isDown = true;
308319
this.isUp = false;
320+
321+
// Work out how long it has been since the last click
322+
this.msSinceLastClick = this.game.time.now - this.timeDown;
323+
309324
this.timeDown = this.game.time.now;
325+
310326
this._holdSent = false;
311327

312328
// This sets the x/y and other local values
@@ -371,10 +387,6 @@ module Phaser {
371387

372388
}
373389

374-
private _highestRenderOrderID: number;
375-
private _highestRenderObject: number;
376-
private _highestInputPriorityID: number;
377-
378390
/**
379391
* Called when the Pointer is moved on the touchscreen
380392
* @method move

Phaser/input/Touch.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ module Phaser {
7979
* @param {Any} event
8080
**/
8181
private consumeTouchMove(event) {
82-
8382
event.preventDefault();
84-
8583
}
8684

8785
/**

0 commit comments

Comments
 (0)