diff --git a/src/game-lib-system-input.js b/src/game-lib-system-input.js index 5bbe6c6..2389b0d 100644 --- a/src/game-lib-system-input.js +++ b/src/game-lib-system-input.js @@ -588,6 +588,8 @@ GameLib.System.Input.prototype.onTouchStart = function(event) { right : 0, up : 0, down : 0, + lastTouchX : event.touches[t].pageX, + lastTouchY : event.touches[t].pageY, pageX : event.touches[t].pageX, pageY : event.touches[t].pageY, cancelled : false, @@ -613,40 +615,43 @@ GameLib.System.Input.prototype.onTouchMove = function (event) { id = event.changedTouches[t].identifier; - var diffX = Math.abs(event.changedTouches[t].pageX - this.touches[id].pageX); - var diffY = Math.abs(event.changedTouches[t].pageY - this.touches[id].pageY); + if (this.touches[id]) { - var left = 0; - var right = 0; - var up = 0; - var down = 0; + var diffX = Math.abs(this.touches[id].lastTouchX - event.changedTouches[id].pageX); + var diffY = Math.abs(this.touches[id].lastTouchY - event.changedTouches[id].pageY); - if (event.changedTouches[t].pageX > this.touches[id].pageX) { - right += diffX; - left -= diffX; + var left = 0; + var right = 0; + var up = 0; + var down = 0; + + if (this.touches[id].lastTouchX < event.changedTouches[id].pageX) { + right += diffX; + } + + if (this.touches[id].lastTouchX > event.changedTouches[id].pageX) { + left += diffX; + } + + if (this.touches[id].lastTouchY > event.changedTouches[id].pageY) { + up += diffY; + } + + if (this.touches[id].lastTouchY < event.changedTouches[id].pageY) { + down += diffY; + } + + this.touches[id].right += right; + this.touches[id].left += left; + this.touches[id].up += up; + this.touches[id].down += down; + this.touches[id].lastTouchX = event.changedTouches[id].pageX; + this.touches[id].lastTouchY = event.changedTouches[id].pageY; + this.touches[id].pageX = event.changedTouches[t].pageX; + this.touches[id].pageY = event.changedTouches[t].pageY; } - if (event.changedTouches[t].pageX < this.touches[id].pageX) { - left += diffX; - right -= diffX; - } - if (event.changedTouches[t].pageY < this.touches[id].pageY) { - up += diffY; - down -= diffY; - } - - if (event.changedTouches[t].pageY > this.touches[id].pageY) { - down += diffY; - up -= diffY; - } - - this.touches[id].right += right; - this.touches[id].left += left; - this.touches[id].up += up; - this.touches[id].down += down; - this.touches[id].pageX = event.changedTouches[t].pageX; - this.touches[id].pageY = event.changedTouches[t].pageY; //console.log(this.touches[id]); }