From 4cc748b3397ab4477b4f5bdcd088ffd1fa68a999 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Sat, 28 Nov 2015 14:48:11 +0800 Subject: [PATCH] Stops sprites flying off if isoPosition is changed during update --- src/IsoSprite.js | 12 ++++++------ src/physics/Body.js | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/IsoSprite.js b/src/IsoSprite.js index c63897e..0ea3d2f 100644 --- a/src/IsoSprite.js +++ b/src/IsoSprite.js @@ -141,8 +141,8 @@ Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype, "isoX", { set: function (value) { this._isoPosition.x = value; this._depthChanged = this._isoPositionChanged = this._isoBoundsChanged = true; - if (this.body && this.body.phase===1){ - this.body.preUpdate(); + if (this.body){ + this.body._reset = true; } } }); @@ -160,8 +160,8 @@ Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype, "isoY", { set: function (value) { this._isoPosition.y = value; this._depthChanged = this._isoPositionChanged = this._isoBoundsChanged = true; - if (this.body.phase===1){ - this.body.preUpdate(); + if (this.body){ + this.body._reset = true; } } }); @@ -179,8 +179,8 @@ Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype, "isoZ", { set: function (value) { this._isoPosition.z = value; this._depthChanged = this._isoPositionChanged = this._isoBoundsChanged = true; - if (this.body.phase===1){ - this.body.preUpdate(); + if (this.body){ + this.body._reset = true; } } }); diff --git a/src/physics/Body.js b/src/physics/Body.js index a734af5..2da3b1e 100644 --- a/src/physics/Body.js +++ b/src/physics/Body.js @@ -544,6 +544,13 @@ Phaser.Plugin.Isometric.Body.prototype = { this.phase = 2; + // stops sprites flying off if isoPosition is changed during update + if (this._reset) { + this.prev.x = this.position.x; + this.prev.y = this.position.y; + this.prev.z = this.position.z; + } + if (this.deltaAbsX() >= this.deltaAbsY() && this.deltaAbsX() >= this.deltaAbsZ()){ if (this.deltaX() < 0) { this.facing = Phaser.Plugin.Isometric.BACKWARDX; @@ -608,6 +615,8 @@ Phaser.Plugin.Isometric.Body.prototype = { this.prev.y = this.position.y; this.prev.z = this.position.z; + this._reset = false; + }, /**