Skip to content

Commit 8843a4a

Browse files
author
mattrick
committed
Add worldAngleToPointer
1 parent c9c8533 commit 8843a4a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/physics/arcade/World.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,4 +1698,21 @@ Phaser.Physics.Arcade.prototype = {
16981698

16991699
}
17001700

1701+
/**
1702+
* Find the angle in radians between a display object (like a Sprite) and a Pointer, taking their x/y and center into account relative to the world.
1703+
*
1704+
* @method Phaser.Physics.Arcade#worldAngleToPointer
1705+
* @param {any} displayObject - The DisplayObjerct to test from.
1706+
* @param {Phaser.Pointer} [pointer] - The Phaser.Pointer to test to. If none is given then Input.activePointer is used.
1707+
* @return {number} The angle in radians between displayObject.x/y to Pointer.x/y
1708+
*/
1709+
worldAngleToPointer: function (displayObject, pointer) {
1710+
pointer = pointer || game.input.activePointer;
1711+
1712+
var dx = pointer.worldX - displayObject.world.x;
1713+
var dy = pointer.worldY - displayObject.world.y;
1714+
1715+
return Math.atan2(dy, dx);
1716+
}
1717+
17011718
};

0 commit comments

Comments
 (0)