InputHandler.enableDrag with a boundsRect set now takes into account the Sprites anchor when limiting the drag (thanks @unindented #1593)

InputHandler.enableDrag with a boundsSprite set now takes into account both the Sprites anchor and the boundsSprite anchor when limiting the drag.
This commit is contained in:
photonstorm 2015-02-16 15:49:46 +00:00
parent 8c23bca62d
commit 9670c8aa86
2 changed files with 37 additions and 16 deletions

View file

@ -132,6 +132,8 @@ Thanks to @pnstickne for vast majority of this update.
* Loader.audiosprite has a new `autoDecode` parameter. If `true` the audio file will be decoded immediately upon load. * Loader.audiosprite has a new `autoDecode` parameter. If `true` the audio file will be decoded immediately upon load.
* Tile.properties is now unique to that specific Tile, and not a reference to the Tileset index bound properties object. Tile.properties can now be modified freely without impacting other tiles sharing the same id (#1254) * Tile.properties is now unique to that specific Tile, and not a reference to the Tileset index bound properties object. Tile.properties can now be modified freely without impacting other tiles sharing the same id (#1254)
* PIXI.TextureSilentFail is a boolean that defaults to `false`. If `true` then `PIXI.Texture.setFrame` will no longer throw an error if the texture dimensions are incorrect. Instead `Texture.valid` will be set to `false` (#1556) * PIXI.TextureSilentFail is a boolean that defaults to `false`. If `true` then `PIXI.Texture.setFrame` will no longer throw an error if the texture dimensions are incorrect. Instead `Texture.valid` will be set to `false` (#1556)
* InputHandler.enableDrag with a boundsRect set now takes into account the Sprites anchor when limiting the drag (thanks @unindented #1593)
* InputHandler.enableDrag with a boundsSprite set now takes into account both the Sprites anchor and the boundsSprite anchor when limiting the drag.
### Bug Fixes ### Bug Fixes

View file

@ -1423,6 +1423,7 @@ Phaser.InputHandler.prototype = {
}, },
/** /**
* Bounds Rect check for the sprite drag * Bounds Rect check for the sprite drag
* @method Phaser.InputHandler#checkBoundsRect * @method Phaser.InputHandler#checkBoundsRect
@ -1451,22 +1452,22 @@ Phaser.InputHandler.prototype = {
} }
else else
{ {
if (this.sprite.x < this.boundsRect.left) if (this.sprite.left < this.boundsRect.left)
{ {
this.sprite.x = this.boundsRect.x; this.sprite.x = this.boundsRect.x + this.sprite.offsetX;
} }
else if ((this.sprite.x + this.sprite.width) > this.boundsRect.right) else if (this.sprite.right > this.boundsRect.right)
{ {
this.sprite.x = this.boundsRect.right - this.sprite.width; this.sprite.x = this.boundsRect.right - (this.sprite.width - this.sprite.offsetX);
} }
if (this.sprite.y < this.boundsRect.top) if (this.sprite.top < this.boundsRect.top)
{ {
this.sprite.y = this.boundsRect.top; this.sprite.y = this.boundsRect.top + this.sprite.offsetY;
} }
else if ((this.sprite.y + this.sprite.height) > this.boundsRect.bottom) else if (this.sprite.bottom > this.boundsRect.bottom)
{ {
this.sprite.y = this.boundsRect.bottom - this.sprite.height; this.sprite.y = this.boundsRect.bottom - (this.sprite.height - this.sprite.offsetY);
} }
} }
@ -1500,23 +1501,41 @@ Phaser.InputHandler.prototype = {
} }
else else
{ {
if (this.sprite.x < this.boundsSprite.x) if (this.sprite.left < this.boundsSprite.left)
{ {
this.sprite.x = this.boundsSprite.x; this.sprite.x = this.boundsSprite.left + this.sprite.offsetX;
} }
else if ((this.sprite.x + this.sprite.width) > (this.boundsSprite.x + this.boundsSprite.width)) else if (this.sprite.right > this.boundsSprite.right)
{ {
this.sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this.sprite.width; this.sprite.x = this.boundsSprite.right - (this.sprite.width - this.sprite.offsetX);
} }
if (this.sprite.y < this.boundsSprite.y) if (this.sprite.top < this.boundsSprite.top)
{ {
this.sprite.y = this.boundsSprite.y; this.sprite.y = this.boundsSprite.top + this.sprite.offsetY;
} }
else if ((this.sprite.y + this.sprite.height) > (this.boundsSprite.y + this.boundsSprite.height)) else if (this.sprite.bottom > this.boundsSprite.bottom)
{ {
this.sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this.sprite.height; this.sprite.y = this.boundsSprite.bottom - (this.sprite.height - this.sprite.offsetY);
} }
// if (this.sprite.x < this.boundsSprite.x)
// {
// this.sprite.x = this.boundsSprite.x;
// }
// else if ((this.sprite.x + this.sprite.width) > (this.boundsSprite.x + this.boundsSprite.width))
// {
// this.sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this.sprite.width;
// }
// if (this.sprite.y < this.boundsSprite.y)
// {
// this.sprite.y = this.boundsSprite.y;
// }
// else if ((this.sprite.y + this.sprite.height) > (this.boundsSprite.y + this.boundsSprite.height))
// {
// this.sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this.sprite.height;
// }
} }
} }