mirror of
https://github.com/photonstorm/phaser
synced 2024-11-16 09:48:18 +00:00
Fixed Input.getLocalPosition.
Updated Input.hitTest so it supports Phaser.Graphics objects.
This commit is contained in:
parent
35d29170d0
commit
6b2dbed96b
1 changed files with 39 additions and 19 deletions
|
@ -773,11 +773,11 @@ Phaser.Input.prototype = {
|
|||
if (typeof output === 'undefined') { output = new Phaser.Point(); }
|
||||
|
||||
var wt = displayObject.worldTransform;
|
||||
var id = 1 / (wt.a * wt.d + wt.b * -wt.c);
|
||||
var id = 1 / (wt.a * wt.d + wt.c * -wt.b);
|
||||
|
||||
return output.setTo(
|
||||
wt.d * id * pointer.x + -wt.b * id * pointer.y + (wt.ty * wt.b - wt.tx * wt.d) * id,
|
||||
wt.a * id * pointer.y + -wt.c * id * pointer.x + (-wt.ty * wt.a + wt.tx * wt.c) * id
|
||||
wt.d * id * pointer.x + -wt.c * id * pointer.y + (wt.ty * wt.c - wt.tx * wt.d) * id,
|
||||
wt.a * id * pointer.y + -wt.b * id * pointer.x + (-wt.ty * wt.a + wt.tx * wt.b) * id
|
||||
);
|
||||
|
||||
},
|
||||
|
@ -805,22 +805,6 @@ Phaser.Input.prototype = {
|
|||
{
|
||||
return (displayObject.hitArea.contains(this._localPoint.x, this._localPoint.y));
|
||||
}
|
||||
else if (displayObject instanceof Phaser.TileSprite)
|
||||
{
|
||||
var width = displayObject.width;
|
||||
var height = displayObject.height;
|
||||
var x1 = -width * displayObject.anchor.x;
|
||||
|
||||
if (this._localPoint.x > x1 && this._localPoint.x < x1 + width)
|
||||
{
|
||||
var y1 = -height * displayObject.anchor.y;
|
||||
|
||||
if (this._localPoint.y > y1 && this._localPoint.y < y1 + height)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (displayObject instanceof PIXI.Sprite)
|
||||
{
|
||||
var width = displayObject.texture.frame.width;
|
||||
|
@ -837,6 +821,42 @@ Phaser.Input.prototype = {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (displayObject instanceof Phaser.TileSprite)
|
||||
{
|
||||
var width = displayObject.width;
|
||||
var height = displayObject.height;
|
||||
var x1 = -width * displayObject.anchor.x;
|
||||
|
||||
if (this._localPoint.x > x1 && this._localPoint.x < x1 + width)
|
||||
{
|
||||
var y1 = -height * displayObject.anchor.y;
|
||||
|
||||
if (this._localPoint.y > y1 && this._localPoint.y < y1 + height)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (displayObject instanceof Phaser.Graphics)
|
||||
{
|
||||
for (var i = 0; i < displayObject.graphicsData.length; i++)
|
||||
{
|
||||
var data = displayObject.graphicsData[i];
|
||||
|
||||
if (!data.fill)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only deal with fills..
|
||||
if (data.shape && data.shape.contains(this._localPoint.x, this._localPoint.y))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Didn't hit the parent, does it have any children?
|
||||
|
||||
for (var i = 0, len = displayObject.children.length; i < len; i++)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue