11/**
22* Phaser - http://www.phaser.io
33*
4- * v1.0.0 - Built at: Fri, 13 Sep 2013 03:04:56 +0000
4+ * v1.0.0 - Built at: Fri, 13 Sep 2013 16:50:35 +0000
55*
66* @author Richard Davey http://www.photonstorm.com @photonstorm
77*
@@ -7396,7 +7396,7 @@ Object.defineProperty(Phaser.Camera.prototype, "height", {
73967396/**
73977397* State
73987398*
7399- * This is a base State class which can be extended if you are creating your game with TypeScript .
7399+ * This is a base State class which can be extended if you are creating your own game .
74007400* It provides quick access to common functions such as the camera, cache, input, match, sound and more.
74017401*
74027402* @package Phaser.State
@@ -7413,7 +7413,7 @@ Phaser.State = function () {
74137413 this.cache = null;
74147414 this.input = null;
74157415 this.load = null;
7416- // this.math = null;
7416+ this.math = null;
74177417 this.sound = null;
74187418 this.stage = null;
74197419 this.time = null;
@@ -7434,7 +7434,7 @@ Phaser.State.prototype = {
74347434 this.cache = game.cache;
74357435 this.input = game.input;
74367436 this.load = game.load;
7437- // this.math = game.math;
7437+ this.math = game.math;
74387438 this.sound = game.sound;
74397439 this.stage = game.stage;
74407440 this.time = game.time;
@@ -7638,6 +7638,7 @@ Phaser.StateManager.prototype = {
76387638 {
76397639 // console.log('Phaser.StateManager.addState: Object given');
76407640 newState = state;
7641+ newState.game = this.game;
76417642 }
76427643 else if (typeof state === 'function')
76437644 {
@@ -7724,9 +7725,10 @@ Phaser.StateManager.prototype = {
77247725
77257726 if (clearWorld) {
77267727
7727- // this.game.world.destroy();
7728+ this.game.world.destroy();
77287729
7729- if (clearCache == true) {
7730+ if (clearCache == true)
7731+ {
77307732 this.game.cache.destroy();
77317733 }
77327734 }
@@ -7994,11 +7996,16 @@ Phaser.LinkedList.prototype = {
79947996
79957997 callAll: function (callback) {
79967998
7999+ if (!this.first || !this.last)
8000+ {
8001+ return;
8002+ }
8003+
79978004 var entity = this.first;
79988005
79998006 do
80008007 {
8001- if (entity[callback])
8008+ if (entity && entity [callback])
80028009 {
80038010 entity[callback].call(entity);
80048011 }
@@ -9513,9 +9520,17 @@ Phaser.Group.prototype = {
95139520
95149521 removeAll: function () {
95159522
9523+ if (this._container.children.length == 0)
9524+ {
9525+ return;
9526+ }
9527+
95169528 do
95179529 {
9518- this._container.children[0].events.onRemovedFromGroup.dispatch(this._container.children[0], this);
9530+ if (this._container.children[0].events)
9531+ {
9532+ this._container.children[0].events.onRemovedFromGroup.dispatch(this._container.children[0], this);
9533+ }
95199534 this._container.removeChild(this._container.children[0]);
95209535 }
95219536 while (this._container.children.length > 0);
@@ -9807,7 +9822,21 @@ Phaser.World.prototype = {
98079822 this.bounds.height = height;
98089823 }
98099824
9810- }
9825+ },
9826+
9827+ /**
9828+ * Destroyer of worlds.
9829+ */
9830+ destroy: function () {
9831+
9832+ this.camera.x = 0;
9833+ this.camera.y = 0;
9834+
9835+ this.game.input.reset(true);
9836+
9837+ this.group.removeAll();
9838+
9839+ }
98119840
98129841};
98139842
@@ -10180,9 +10209,9 @@ Phaser.Game.prototype = {
1018010209
1018110210 this.stage.boot();
1018210211 this.world.boot();
10183- this.state.boot();
1018410212 this.input.boot();
1018510213 this.sound.boot();
10214+ this.state.boot();
1018610215
1018710216 if (this.renderType == Phaser.CANVAS)
1018810217 {
@@ -10243,9 +10272,6 @@ Phaser.Game.prototype = {
1024310272
1024410273 this.state.loadComplete();
1024510274
10246- // ?
10247- // this.load.onLoadComplete.remove(this.loadComplete, this);
10248-
1024910275 },
1025010276
1025110277 update: function (time) {
@@ -10618,14 +10644,6 @@ Phaser.Input.prototype = {
1061810644 this.hitCanvas.height = 1;
1061910645 this.hitContext = this.hitCanvas.getContext('2d');
1062010646
10621- // Debugging
10622- // this.hitCanvas.style['width'] = '200px';
10623- // this.hitCanvas.style['height'] = '200px';
10624- // this.hitCanvas.style['position'] = 'absolute';
10625- // this.hitCanvas.style['left'] = '810px';
10626- // this.hitCanvas.style['backgroundColor'] = '#ef0000';
10627- // Phaser.Canvas.addToDOM(this.hitCanvas);
10628-
1062910647 this.mouse.start();
1063010648 this.keyboard.start();
1063110649 this.touch.start();
@@ -10705,7 +10723,12 @@ Phaser.Input.prototype = {
1070510723 **/
1070610724 reset: function (hard) {
1070710725
10708- hard = hard || false;
10726+ if (this.game.isBooted == false)
10727+ {
10728+ return;
10729+ }
10730+
10731+ if (typeof hard == 'undefined') { hard = false; }
1070910732
1071010733 this.keyboard.reset();
1071110734 this.mousePointer.reset();
@@ -13247,9 +13270,10 @@ Phaser.InputHandler.prototype = {
1324713270 */
1324813271 enableDrag: function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
1324913272
13250- lockCenter = lockCenter || false;
13251- bringToTop = bringToTop || false;
13252- pixelPerfect = pixelPerfect || false;
13273+ if (typeof lockCenter == 'undefined') { lockCenter = false; }
13274+ if (typeof bringToTop == 'undefined') { bringToTop = false; }
13275+ if (typeof pixelPerfect == 'undefined') { pixelPerfect = false; }
13276+
1325313277 alphaThreshold = alphaThreshold || 255;
1325413278 boundsRect = boundsRect || null;
1325513279 boundsSprite = boundsSprite || null;
@@ -13305,7 +13329,7 @@ Phaser.InputHandler.prototype = {
1330513329
1330613330 if (this.dragFromCenter)
1330713331 {
13308- // this.sprite.transform. centerOn(pointer.worldX , pointer.worldY );
13332+ this.sprite.centerOn(pointer.x , pointer.y );
1330913333 this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y);
1331013334 }
1331113335 else
@@ -13371,13 +13395,13 @@ Phaser.InputHandler.prototype = {
1337113395 */
1337213396 enableSnap: function (snapX, snapY, onDrag, onRelease) {
1337313397
13374- onDrag = onDrag || true;
13375- onRelease = onRelease || false;
13398+ if (typeof onDrag == 'undefined') { onDrag = true; }
13399+ if (typeof onRelease == 'undefined') { onRelease = false; }
1337613400
13377- this.snapOnDrag = onDrag;
13378- this.snapOnRelease = onRelease;
1337913401 this.snapX = snapX;
1338013402 this.snapY = snapY;
13403+ this.snapOnDrag = onDrag;
13404+ this.snapOnRelease = onRelease;
1338113405
1338213406 },
1338313407
@@ -14124,6 +14148,17 @@ Phaser.Sprite.prototype.preUpdate = function() {
1412414148
1412514149}
1412614150
14151+ /**
14152+ * Moves the sprite so its center is located on the given x and y coordinates.
14153+ * Doesn't change the origin of the sprite.
14154+ */
14155+ Phaser.Sprite.prototype.centerOn = function(x, y) {
14156+
14157+ this.x = x + (this.x - this.center.x);
14158+ this.y = y + (this.y - this.center.y);
14159+
14160+ }
14161+
1412714162Phaser.Sprite.prototype.revive = function() {
1412814163
1412914164 this.alive = true;
@@ -14436,6 +14471,9 @@ Phaser.Text = function (game, x, y, text, style) {
1443614471 text = text || '';
1443714472 style = style || '';
1443814473
14474+ PIXI.Text.call(this, text, style);
14475+
14476+ /*
1443914477 this.canvas = document.createElement("canvas");
1444014478 this.context = this.canvas.getContext("2d");
1444114479
@@ -14452,10 +14490,12 @@ Phaser.Text = function (game, x, y, text, style) {
1445214490
1445314491 this.updateText();
1445414492 this.dirty = false;
14493+ */
1445514494
1445614495};
1445714496
14458- Phaser.Text.prototype = Phaser.Utils.extend(true, Phaser.Sprite.prototype, PIXI.Text.prototype);
14497+ // Phaser.Text.prototype = Phaser.Utils.extend(true, Phaser.Sprite.prototype, PIXI.Text.prototype);
14498+ Phaser.Text.prototype = Phaser.Utils.extend(true, PIXI.Text.prototype);
1445914499Phaser.Text.prototype.constructor = Phaser.Text;
1446014500
1446114501// Add our own custom methods
@@ -21317,10 +21357,10 @@ Phaser.Animation.Parser = {
2131721357 ));
2131821358
2131921359 PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
21320- x: frames[key ].frame.x,
21321- y: frames[key ].frame.y,
21322- width: frames[key ].frame.w,
21323- height: frames[key ].frame.h
21360+ x: frames[i ].frame.x,
21361+ y: frames[i ].frame.y,
21362+ width: frames[i ].frame.w,
21363+ height: frames[i ].frame.h
2132421364 });
2132521365
2132621366 if (frames[i].trimmed)
@@ -21335,7 +21375,7 @@ Phaser.Animation.Parser = {
2133521375 frames[i].spriteSourceSize.h
2133621376 );
2133721377
21338- PIXI.TextureCache[uuid].realSize = frames[key ].spriteSourceSize;
21378+ PIXI.TextureCache[uuid].realSize = frames[i ].spriteSourceSize;
2133921379 PIXI.TextureCache[uuid].trim.x = 0;
2134021380 }
2134121381 }
@@ -24944,11 +24984,11 @@ Phaser.Physics.Arcade.prototype = {
2494424984 },
2494524985
2494624986 /**
24947- * Checks for collision between two game objects. The objects can be Sprites, Groups or Tilemaps.
24987+ * Checks for collision between two game objects. The objects can be Sprites, Groups, Emitters or Tilemaps.
2494824988 * You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap or Group vs. Tilemap collisions.
2494924989 *
24950- * @param object1 The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group or Phaser.Tilemap
24951- * @param object2 The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group or Phaser.Tilemap
24990+ * @param object1 The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.Tilemap
24991+ * @param object2 The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.Tilemap
2495224992 * @param collideCallback An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
2495324993 * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true.
2495424994 * @param callbackContext The context in which to run the callbacks.
@@ -24968,55 +25008,65 @@ Phaser.Physics.Arcade.prototype = {
2496825008 {
2496925009 // Can expand to support Buttons, Text, etc at a later date. For now these are the essentials.
2497025010
24971- // SPRITE vs. SPRITE
24972- if (object1.type == Phaser.SPRITE && object2.type == Phaser.SPRITE)
24973- {
24974- this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext);
24975- }
24976- // SPRITE vs. GROUP
24977- else if (object1.type == Phaser.SPRITE && object2.type == Phaser.GROUP)
24978- {
24979- this.collideSpriteVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
24980- }
24981- // GROUP vs. SPRITE
24982- else if (object1.type == Phaser.GROUP && object2.type == Phaser.SPRITE)
25011+ // SPRITES
25012+ if (object1.type == Phaser.SPRITE)
2498325013 {
24984- this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
24985- }
24986- // GROUP vs. GROUP
24987- else if (object1.type == Phaser.GROUP && object2.type == Phaser.GROUP)
24988- {
24989- this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
24990- }
24991- // SPRITE vs. TILEMAP
24992- else if (object1.type == Phaser.SPRITE && object2.type == Phaser.TILEMAP)
24993- {
24994- this.collideSpriteVsTilemap(object1, object2, collideCallback, processCallback, callbackContext);
24995- }
24996- // TILEMAP vs. SPRITE
24997- else if (object1.type == Phaser.TILEMAP && object2.type == Phaser.SPRITE)
24998- {
24999- this.collideSpriteVsTilemap(object2, object1, collideCallback, processCallback, callbackContext);
25000- }
25001- // GROUP vs. TILEMAP
25002- else if (object1.type == Phaser.GROUP && object2.type == Phaser.TILEMAP)
25003- {
25004- this.collideGroupVsTilemap(object1, object2, collideCallback, processCallback, callbackContext);
25014+ if (object2.type == Phaser.SPRITE)
25015+ {
25016+ this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext);
25017+ }
25018+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
25019+ {
25020+ this.collideSpriteVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
25021+ }
25022+ else if (object2.type == Phaser.TILEMAP)
25023+ {
25024+ this.collideSpriteVsTilemap(object1, object2, collideCallback, processCallback, callbackContext);
25025+ }
2500525026 }
25006- // TILEMAP vs. GROUP
25007- else if (object1.type == Phaser.TILEMAP && object2.type == Phaser. GROUP)
25027+ // GROUPS
25028+ else if (object1.type == Phaser.GROUP)
2500825029 {
25009- this.collideGroupVsTilemap(object2, object1, collideCallback, processCallback, callbackContext);
25030+ if (object2.type == Phaser.SPRITE)
25031+ {
25032+ this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
25033+ }
25034+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
25035+ {
25036+ this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
25037+ }
25038+ else if (object2.type == Phaser.TILEMAP)
25039+ {
25040+ this.collideGroupVsTilemap(object1, object2, collideCallback, processCallback, callbackContext);
25041+ }
2501025042 }
25011- // EMITTER vs. TILEMAP
25012- else if (object1.type == Phaser.EMITTER && object2.type == Phaser. TILEMAP)
25043+ // TILEMAPS
25044+ else if (object1.type == Phaser.TILEMAP)
2501325045 {
25014- this.collideGroupVsTilemap(object1, object2, collideCallback, processCallback, callbackContext);
25046+ if (object2.type == Phaser.SPRITE)
25047+ {
25048+ this.collideSpriteVsTilemap(object2, object1, collideCallback, processCallback, callbackContext);
25049+ }
25050+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
25051+ {
25052+ this.collideGroupVsTilemap(object2, object1, collideCallback, processCallback, callbackContext);
25053+ }
2501525054 }
25016- // TILEMAP vs. EMITTER
25017- else if (object1.type == Phaser.TILEMAP && object2.type == Phaser. EMITTER)
25055+ // EMITTER
25056+ else if (object1.type == Phaser.EMITTER)
2501825057 {
25019- this.collideGroupVsTilemap(object2, object1, collideCallback, processCallback, callbackContext);
25058+ if (object2.type == Phaser.SPRITE)
25059+ {
25060+ this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
25061+ }
25062+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
25063+ {
25064+ this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
25065+ }
25066+ else if (object2.type == Phaser.TILEMAP)
25067+ {
25068+ this.collideGroupVsTilemap(object1, object2, collideCallback, processCallback, callbackContext);
25069+ }
2502025070 }
2502125071 }
2502225072
0 commit comments