First pass at scale handling on drag. Enable with: sprite.input.scaleLayer = true;

This commit is contained in:
photonstorm 2014-09-25 17:01:27 +01:00
parent 415c7fe578
commit 319146292b

View file

@ -172,6 +172,11 @@ Phaser.InputHandler = function (sprite) {
*/ */
this.consumePointerEvent = false; 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. * @property {boolean} _dragPhase - Internal cache var.
* @private * @private
@ -1009,16 +1014,19 @@ Phaser.InputHandler.prototype = {
return false; 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.sprite.fixedToCamera)
{ {
if (this.allowHorizontalDrag) if (this.allowHorizontalDrag)
{ {
this.sprite.cameraOffset.x = pointer.x + this._dragPoint.x + this.dragOffset.x; this.sprite.cameraOffset.x = px;
} }
if (this.allowVerticalDrag) if (this.allowVerticalDrag)
{ {
this.sprite.cameraOffset.y = pointer.y + this._dragPoint.y + this.dragOffset.y; this.sprite.cameraOffset.y = py;
} }
if (this.boundsRect) if (this.boundsRect)
@ -1041,12 +1049,12 @@ Phaser.InputHandler.prototype = {
{ {
if (this.allowHorizontalDrag) if (this.allowHorizontalDrag)
{ {
this.sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x; this.sprite.x = px;
} }
if (this.allowVerticalDrag) if (this.allowVerticalDrag)
{ {
this.sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y; this.sprite.y = py;
} }
if (this.boundsRect) if (this.boundsRect)
@ -1260,14 +1268,15 @@ Phaser.InputHandler.prototype = {
if (this.dragFromCenter) if (this.dragFromCenter)
{ {
var bounds = this.sprite.getBounds(); var bounds = this.sprite.getBounds();
this.sprite.x = pointer.x + (this.sprite.x - bounds.centerX); this.sprite.x = this.globalToLocalX(pointer.x) + (this.sprite.x - bounds.centerX);
this.sprite.y = pointer.y + (this.sprite.y - bounds.centerY); 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); // 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);
} }
// 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); 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. * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
* @method Phaser.InputHandler#stopDrag * @method Phaser.InputHandler#stopDrag