mirror of
https://github.com/photonstorm/phaser
synced 2024-12-03 09:59:42 +00:00
PointScreenToWorldHitTest added to Global Input Manager
This commit is contained in:
parent
423326c71b
commit
ebea116809
4 changed files with 69 additions and 14 deletions
|
@ -70,6 +70,10 @@ var Camera = new Class({
|
|||
for (var index = 0; index < length; ++index)
|
||||
{
|
||||
var object = renderableObjects[index];
|
||||
|
||||
/* Not every renderable object has a dimension */
|
||||
if (typeof object.width === 'number')
|
||||
{
|
||||
var objectW = object.width;
|
||||
var objectH = object.height;
|
||||
var objectX = (object.x - (scrollX * object.scrollFactorX)) - (objectW * object.originX);
|
||||
|
@ -83,6 +87,11 @@ var Camera = new Class({
|
|||
culledObjects.push(object);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
culledObjects.push(object);
|
||||
}
|
||||
}
|
||||
|
||||
return culledObjects;
|
||||
},
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
var IntersectGameObject = function (point, gameObjectArray, camera)
|
||||
{
|
||||
return false;
|
||||
};
|
||||
|
||||
module.exports = IntersectGameObject;
|
|
@ -8,6 +8,7 @@ var Mouse = require('./mouse/MouseManager');
|
|||
var MouseEvent = require('./mouse/events/');
|
||||
var PointWithinGameObject = require('./components/PointWithinGameObject');
|
||||
var TransformMatrix = require('../gameobjects/components/TransformMatrix');
|
||||
var PointScreenToWorldHitTest = require('./components/PointScreenToWorldHitTest');
|
||||
|
||||
var GlobalInputManager = new Class({
|
||||
|
||||
|
@ -32,6 +33,7 @@ var GlobalInputManager = new Class({
|
|||
|
||||
this._tempMatrix = new TransformMatrix();
|
||||
this._tempPoint = { x: 0, y: 0 };
|
||||
this._tempHitTest = [];
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -92,6 +94,11 @@ var GlobalInputManager = new Class({
|
|||
pointWithinGameObject: function (gameObject, x, y)
|
||||
{
|
||||
return PointWithinGameObject(gameObject, x, y);
|
||||
},
|
||||
|
||||
pointScreenToWorldHitTest: function (gameObjects, x, y, camera)
|
||||
{
|
||||
return PointScreenToWorldHitTest(this._tempMatrix, x, y, gameObjects, camera, this._tempHitTest);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
45
v3/src/input/components/PointScreenToWorldHitTest.js
Normal file
45
v3/src/input/components/PointScreenToWorldHitTest.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
var GetTransformedPoint = require('./GetTransformedPoint');
|
||||
var PointWithinGameObject = require('./PointWithinGameObject');
|
||||
|
||||
var PointScreenToWorldHitTest = function (tempMatrix, x, y, gameObjectArray, camera, output)
|
||||
{
|
||||
var length = gameObjectArray.length;
|
||||
var scrollX = camera.scrollX;
|
||||
var scrollY = camera.scrollY;
|
||||
var cameraW = camera.width;
|
||||
var cameraH = camera.height;
|
||||
|
||||
output.length = 0;
|
||||
|
||||
if (gameObjectArray instanceof Array)
|
||||
{
|
||||
var culled = camera.cull(gameObjectArray);
|
||||
var culledLength = culled.length;
|
||||
|
||||
for (var index = 0; index < culledLength; ++index)
|
||||
{
|
||||
var object = culled[index];
|
||||
var tpoint = GetTransformedPoint(tempMatrix, object, x + scrollX * object.scrollFactorX, y + scrollY * object.scrollFactorY);
|
||||
|
||||
if (PointWithinGameObject(object, tpoint.x, tpoint.y))
|
||||
{
|
||||
output.push(object);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
else
|
||||
{
|
||||
var tpoint = GetTransformedPoint(tempMatrix, object, x + scrollX * object.scrollFactorX, y + scrollY * object.scrollFactorY);
|
||||
|
||||
if (PointWithinGameObject(object, tpoint.x, tpoint.y))
|
||||
{
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
module.exports = PointScreenToWorldHitTest;
|
Loading…
Reference in a new issue