diff --git a/src/input/InputHandler.js b/src/input/InputHandler.js index eb3f71be3..3cdad9e65 100644 --- a/src/input/InputHandler.js +++ b/src/input/InputHandler.js @@ -172,6 +172,11 @@ Phaser.InputHandler = function (sprite) { */ this.consumePointerEvent = false; + /** + * @property {boolean} scaleLayer - EXPERIMENTAL: Please do not use this property unless you know what it does. Likely to change in the future. + */ + this.scaleLayer = false; + /** * @property {boolean} _dragPhase - Internal cache var. * @private @@ -1009,16 +1014,19 @@ Phaser.InputHandler.prototype = { return false; } + var px = this.globalToLocalX(pointer.x) + this._dragPoint.x + this.dragOffset.x; + var py = this.globalToLocalY(pointer.y) + this._dragPoint.y + this.dragOffset.y; + if (this.sprite.fixedToCamera) { if (this.allowHorizontalDrag) { - this.sprite.cameraOffset.x = pointer.x + this._dragPoint.x + this.dragOffset.x; + this.sprite.cameraOffset.x = px; } if (this.allowVerticalDrag) { - this.sprite.cameraOffset.y = pointer.y + this._dragPoint.y + this.dragOffset.y; + this.sprite.cameraOffset.y = py; } if (this.boundsRect) @@ -1041,12 +1049,12 @@ Phaser.InputHandler.prototype = { { if (this.allowHorizontalDrag) { - this.sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x; + this.sprite.x = px; } if (this.allowVerticalDrag) { - this.sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y; + this.sprite.y = py; } if (this.boundsRect) @@ -1260,14 +1268,15 @@ Phaser.InputHandler.prototype = { if (this.dragFromCenter) { var bounds = this.sprite.getBounds(); - this.sprite.x = pointer.x + (this.sprite.x - bounds.centerX); - this.sprite.y = pointer.y + (this.sprite.y - bounds.centerY); - this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y); - } - else - { - this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y); + this.sprite.x = this.globalToLocalX(pointer.x) + (this.sprite.x - bounds.centerX); + this.sprite.y = this.globalToLocalY(pointer.y) + (this.sprite.y - bounds.centerY); + // this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y); } + // else + // { + // this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y); + this._dragPoint.setTo(this.sprite.x - this.globalToLocalX(pointer.x), this.sprite.y - this.globalToLocalY(pointer.y)); + // } } this.updateDrag(pointer); @@ -1282,6 +1291,40 @@ Phaser.InputHandler.prototype = { }, + /** + * Warning: EXPERIMENTAL + * @method Phaser.InputHandler#globalToLocalX + * @param {number} x + */ + globalToLocalX: function (x) { + + if (this.scaleLayer) + { + x -= this.game.scale.grid.boundsFluid.x; + x *= this.game.scale.grid.scaleFluidInversed.x; + } + + return x; + + }, + + /** + * Warning: EXPERIMENTAL + * @method Phaser.InputHandler#globalToLocalY + * @param {number} y + */ + globalToLocalY: function (y) { + + if (this.scaleLayer) + { + y -= this.game.scale.grid.boundsFluid.y; + y *= this.game.scale.grid.scaleFluidInversed.y; + } + + return y; + + }, + /** * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly. * @method Phaser.InputHandler#stopDrag