mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Added start of the transformed point functions
This commit is contained in:
parent
3daafa7c04
commit
e7465bb17f
4 changed files with 61 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '214dcc80-5097-11e7-9900-0395e9b33639'
|
||||
build: '927d4eb0-509e-11e7-8474-0fbd363270fe'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -4,6 +4,9 @@ var Keyboard = require('./keyboard/KeyboardManager');
|
|||
var Mouse = require('./mouse/MouseManager');
|
||||
var MouseEvent = require('./mouse/events/');
|
||||
var EventDispatcher = require('../events/EventDispatcher');
|
||||
var GetTransformedPoint = require('./components/GetTransformedPoint');
|
||||
var PointWithinGameObject = require('./components/PointWithinGameObject');
|
||||
var TransformMatrix = require('../components/TransformMatrix');
|
||||
|
||||
var GlobalInputManager = function (game, gameConfig)
|
||||
{
|
||||
|
@ -21,6 +24,9 @@ var GlobalInputManager = function (game, gameConfig)
|
|||
// Listeners
|
||||
this.keyboard = new Keyboard(this);
|
||||
this.mouse = new Mouse(this);
|
||||
|
||||
this._tempMatrix = new TransformMatrix();
|
||||
this._tempPoint = { x: 0, y: 0 };
|
||||
};
|
||||
|
||||
GlobalInputManager.prototype.constructor = GlobalInputManager;
|
||||
|
@ -75,6 +81,16 @@ GlobalInputManager.prototype = {
|
|||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
getTransformedPoint: function (gameObject, x, y)
|
||||
{
|
||||
return GetTransformedPoint(this._tempMatrix, gameObject, x, y, this._tempPoint);
|
||||
},
|
||||
|
||||
pointWithinGameObject: function (gameObject, x, y)
|
||||
{
|
||||
return PointWithinGameObject(gameObject, x, y);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
30
v3/src/input/components/GetTransformedPoint.js
Normal file
30
v3/src/input/components/GetTransformedPoint.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* This will return the local coordinates of the specified displayObject based on the given Pointer.
|
||||
*
|
||||
* @method Phaser.Input#getLocalPosition
|
||||
* @param {Phaser.Sprite|Phaser.Image} gameObject - The DisplayObject to get the local coordinates for.
|
||||
* @param {Phaser.Pointer} pointer - The Pointer to use in the check against the gameObject.
|
||||
* @return {Phaser.Point} A point containing the coordinates of the Pointer position relative to the DisplayObject.
|
||||
*/
|
||||
var GetTransformedPoint = function (matrix, gameObject, x, y, output)
|
||||
{
|
||||
if (output === undefined) { output = { x: 0, y: 0 }; }
|
||||
|
||||
matrix.applyITRS(gameObject.x, gameObject.y, gameObject.rotation, gameObject.scaleX, gameObject.scaleY);
|
||||
|
||||
var a = matrix.matrix[0];
|
||||
var b = matrix.matrix[1];
|
||||
var c = matrix.matrix[2];
|
||||
var d = matrix.matrix[3];
|
||||
var tx = matrix.matrix[4];
|
||||
var ty = matrix.matrix[5];
|
||||
|
||||
var id = 1 / (a * d + c * -b);
|
||||
|
||||
output.x = d * id * x + -c * id * y + (ty * c - tx * d) * id;
|
||||
output.y = a * id * y + -b * id * x + (-ty * a + tx * b) * id;
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
module.exports = GetTransformedPoint;
|
14
v3/src/input/components/PointWithinGameObject.js
Normal file
14
v3/src/input/components/PointWithinGameObject.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
// x/y MUST be translated before being passed to this function, unless the gameObject is guarnateed to
|
||||
// be not rotated or scaled in any way
|
||||
|
||||
var PointWithinGameObject = function (gameObject, x, y)
|
||||
{
|
||||
var width = gameObject.width;
|
||||
var height = gameObject.height;
|
||||
var x1 = -width * gameObject.originX;
|
||||
var y1 = -height * gameObject.originY;
|
||||
|
||||
return (x >= x1 && x < x1 + width && y >= y1 && y < y1 + height);
|
||||
};
|
||||
|
||||
module.exports = PointWithinGameObject;
|
Loading…
Add table
Reference in a new issue