diff --git a/src/pixi/InteractionData.js b/src/pixi/InteractionData.js index 9274ad1..ea77370 100644 --- a/src/pixi/InteractionData.js +++ b/src/pixi/InteractionData.js @@ -1,7 +1,7 @@ /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ - + /** * Holds all information related to an Interaction event * @@ -18,7 +18,7 @@ */ this.global = new PIXI.Point(); - + /** * The target Sprite that was interacted with * @@ -41,9 +41,10 @@ * * @method getLocalPosition * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off + * @param [point] {Point} A Point object in which to store the value, optional (otherwise will create a new point) * @return {Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject */ -PIXI.InteractionData.prototype.getLocalPosition = function(displayObject) +PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point) { var worldTransform = displayObject.worldTransform; var global = this.global; @@ -52,10 +53,15 @@ var a00 = worldTransform.a, a01 = worldTransform.b, a02 = worldTransform.tx, a10 = worldTransform.c, a11 = worldTransform.d, a12 = worldTransform.ty, id = 1 / (a00 * a11 + a01 * -a10); + + point = point || new PIXI.Point(); + + point.x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id; + point.y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id; + // set the mouse coords... - return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id); + return point; }; // constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; \ No newline at end of file +PIXI.InteractionData.prototype.constructor = PIXI.InteractionData;