From 43d9fc4f52c4fbc5289ec3906810f2eecc52c58a Mon Sep 17 00:00:00 2001 From: photonstorm Date: Tue, 11 Feb 2014 04:08:32 +0000 Subject: [PATCH] Fixed issue where loadTexture would sometimes incorrectly try to apply the texture update twice. Also fixed bug in Math.angleBetween. --- src/gameobjects/Image.js | 8 ++++++++ src/gameobjects/Sprite.js | 6 ++++++ src/math/Math.js | 13 ++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/gameobjects/Image.js b/src/gameobjects/Image.js index dc66d9c77..7c8fa9816 100644 --- a/src/gameobjects/Image.js +++ b/src/gameobjects/Image.js @@ -178,16 +178,19 @@ Phaser.Image.prototype.loadTexture = function (key, frame) { { this.key = key.key; this.setTexture(key); + return; } else if (key instanceof Phaser.BitmapData) { this.key = key.key; this.setTexture(key.texture); + return; } else if (key instanceof PIXI.Texture) { this.key = key; this.setTexture(key); + return; } else { @@ -195,11 +198,13 @@ Phaser.Image.prototype.loadTexture = function (key, frame) { { this.key = '__default'; this.setTexture(PIXI.TextureCache[this.key]); + return; } else if (typeof key === 'string' && !this.game.cache.checkImageKey(key)) { this.key = '__missing'; this.setTexture(PIXI.TextureCache[this.key]); + return; } if (this.game.cache.isSpriteSheet(key)) @@ -213,18 +218,21 @@ Phaser.Image.prototype.loadTexture = function (key, frame) { this._frame = 0; this._frameName = frame; this.setTexture(PIXI.TextureCache[frameData.getFrameByName(frame).uuid]); + return; } else { this._frame = frame; this._frameName = ''; this.setTexture(PIXI.TextureCache[frameData.getFrame(frame).uuid]); + return; } } else { this.key = key; this.setTexture(PIXI.TextureCache[key]); + return; } } diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index a54cb14c4..cf8b232e4 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -323,16 +323,19 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) { { this.key = key.key; this.setTexture(key); + return; } else if (key instanceof Phaser.BitmapData) { this.key = key.key; this.setTexture(key.texture); + return; } else if (key instanceof PIXI.Texture) { this.key = key; this.setTexture(key); + return; } else { @@ -340,11 +343,13 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) { { this.key = '__default'; this.setTexture(PIXI.TextureCache[this.key]); + return; } else if (typeof key === 'string' && !this.game.cache.checkImageKey(key)) { this.key = '__missing'; this.setTexture(PIXI.TextureCache[this.key]); + return; } if (this.game.cache.isSpriteSheet(key)) @@ -367,6 +372,7 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) { { this.key = key; this.setTexture(PIXI.TextureCache[key]); + return; } } diff --git a/src/math/Math.js b/src/math/Math.js index bb1c6f796..fd1dfd895 100644 --- a/src/math/Math.js +++ b/src/math/Math.js @@ -336,7 +336,18 @@ Phaser.Math = { * @return {number} */ angleBetween: function (x1, y1, x2, y2) { - return Math.atan2(y2 - y1, x2 - x1); + return Math.atan2(x2 - x1, y2 - y1); + }, + + /** + * Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y). + * @method Phaser.Math#angleBetweenPoints + * @param {Phaser.Point} point1 + * @param {Phaser.Point} point2 + * @return {number} + */ + angleBetweenPoints: function (point1, point2) { + return Math.atan2(point2.x - point1.x, point2.y - point1.y); }, /**