Add worldAngleToPointer

This commit is contained in:
mattrick 2015-10-27 16:55:23 -07:00
parent c9c85330ab
commit 8843a4ad09

View file

@ -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);
}
}; };