mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 16:39:34 +00:00
Add worldAngleToPointer
This commit is contained in:
parent
c9c85330ab
commit
8843a4ad09
1 changed files with 17 additions and 0 deletions
|
@ -1698,4 +1698,21 @@ Phaser.Physics.Arcade.prototype = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @method Phaser.Physics.Arcade#worldAngleToPointer
|
||||||
|
* @param {any} displayObject - The DisplayObjerct to test from.
|
||||||
|
* @param {Phaser.Pointer} [pointer] - The Phaser.Pointer to test to. If none is given then Input.activePointer is used.
|
||||||
|
* @return {number} The angle in radians between displayObject.x/y to Pointer.x/y
|
||||||
|
*/
|
||||||
|
worldAngleToPointer: function (displayObject, pointer) {
|
||||||
|
pointer = pointer || game.input.activePointer;
|
||||||
|
|
||||||
|
var dx = pointer.worldX - displayObject.world.x;
|
||||||
|
var dy = pointer.worldY - displayObject.world.y;
|
||||||
|
|
||||||
|
return Math.atan2(dy, dx);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue