Skip to content

Commit 6b2dbed

Browse files
committed
Fixed Input.getLocalPosition.
Updated Input.hitTest so it supports Phaser.Graphics objects.
1 parent 35d2917 commit 6b2dbed

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

src/input/Input.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,11 @@ Phaser.Input.prototype = {
773773
if (typeof output === 'undefined') { output = new Phaser.Point(); }
774774

775775
var wt = displayObject.worldTransform;
776-
var id = 1 / (wt.a * wt.d + wt.b * -wt.c);
776+
var id = 1 / (wt.a * wt.d + wt.c * -wt.b);
777777

778778
return output.setTo(
779-
wt.d * id * pointer.x + -wt.b * id * pointer.y + (wt.ty * wt.b - wt.tx * wt.d) * id,
780-
wt.a * id * pointer.y + -wt.c * id * pointer.x + (-wt.ty * wt.a + wt.tx * wt.c) * id
779+
wt.d * id * pointer.x + -wt.c * id * pointer.y + (wt.ty * wt.c - wt.tx * wt.d) * id,
780+
wt.a * id * pointer.y + -wt.b * id * pointer.x + (-wt.ty * wt.a + wt.tx * wt.b) * id
781781
);
782782

783783
},
@@ -805,10 +805,10 @@ Phaser.Input.prototype = {
805805
{
806806
return (displayObject.hitArea.contains(this._localPoint.x, this._localPoint.y));
807807
}
808-
else if (displayObject instanceof Phaser.TileSprite)
808+
else if (displayObject instanceof PIXI.Sprite)
809809
{
810-
var width = displayObject.width;
811-
var height = displayObject.height;
810+
var width = displayObject.texture.frame.width;
811+
var height = displayObject.texture.frame.height;
812812
var x1 = -width * displayObject.anchor.x;
813813

814814
if (this._localPoint.x > x1 && this._localPoint.x < x1 + width)
@@ -821,10 +821,10 @@ Phaser.Input.prototype = {
821821
}
822822
}
823823
}
824-
else if (displayObject instanceof PIXI.Sprite)
824+
else if (displayObject instanceof Phaser.TileSprite)
825825
{
826-
var width = displayObject.texture.frame.width;
827-
var height = displayObject.texture.frame.height;
826+
var width = displayObject.width;
827+
var height = displayObject.height;
828828
var x1 = -width * displayObject.anchor.x;
829829

830830
if (this._localPoint.x > x1 && this._localPoint.x < x1 + width)
@@ -837,6 +837,26 @@ Phaser.Input.prototype = {
837837
}
838838
}
839839
}
840+
else if (displayObject instanceof Phaser.Graphics)
841+
{
842+
for (var i = 0; i < displayObject.graphicsData.length; i++)
843+
{
844+
var data = displayObject.graphicsData[i];
845+
846+
if (!data.fill)
847+
{
848+
continue;
849+
}
850+
851+
// Only deal with fills..
852+
if (data.shape && data.shape.contains(this._localPoint.x, this._localPoint.y))
853+
{
854+
return true;
855+
}
856+
}
857+
}
858+
859+
// Didn't hit the parent, does it have any children?
840860

841861
for (var i = 0, len = displayObject.children.length; i < len; i++)
842862
{

0 commit comments

Comments
 (0)