From d3d00c1624a2a9235401d0a04a56612f86064c34 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Sat, 28 Nov 2015 13:03:41 +0800 Subject: [PATCH] sprite.body.facing snaps to fastest movement direction --- src/physics/Body.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/physics/Body.js b/src/physics/Body.js index 833697b..d3295d5 100644 --- a/src/physics/Body.js +++ b/src/physics/Body.js @@ -540,22 +540,24 @@ Phaser.Plugin.Isometric.Body.prototype = { this.phase = 2; - if (this.deltaX() < 0) { - this.facing = Phaser.Plugin.Isometric.BACKWARDX; - } else if (this.deltaX() > 0) { - this.facing = Phaser.Plugin.Isometric.FORWARDX; - } - - if (this.deltaY() < 0) { - this.facing = Phaser.Plugin.Isometric.BACKWARDY; - } else if (this.deltaY() > 0) { - this.facing = Phaser.Plugin.Isometric.FORWARDY; - } - - if (this.deltaZ() < 0) { - this.facing = Phaser.Plugin.Isometric.DOWN; - } else if (this.deltaZ() > 0) { - this.facing = Phaser.Plugin.Isometric.UP; + if (this.deltaAbsX() >= this.deltaAbsY() && this.deltaAbsX() >= this.deltaAbsZ()){ + if (this.deltaX() < 0) { + this.facing = Phaser.Plugin.Isometric.BACKWARDX; + } else if (this.deltaX() > 0) { + this.facing = Phaser.Plugin.Isometric.FORWARDX; + } + } else if (this.deltaAbsY() >= this.deltaAbsX() && this.deltaAbsY() >= this.deltaAbsZ()){ + if (this.deltaY() < 0) { + this.facing = Phaser.Plugin.Isometric.BACKWARDY; + } else if (this.deltaY() > 0) { + this.facing = Phaser.Plugin.Isometric.FORWARDY; + } + } else { + if (this.deltaZ() < 0) { + this.facing = Phaser.Plugin.Isometric.DOWN; + } else if (this.deltaZ() > 0) { + this.facing = Phaser.Plugin.Isometric.UP; + } } if (this.moves) {