Merge remote-tracking branch 'origin/master'

This commit is contained in:
Pavle Goloskokovic 2017-11-28 16:34:48 +01:00
commit e9a71beba7
7 changed files with 78 additions and 9 deletions

View file

@ -77,6 +77,8 @@ var Camera = new Class({
ignore: require('./inc/Ignore'),
preRender: require('./inc/PreRender'),
removeBounds: require('./inc/RemoveBounds'),
screenToCamera: require('./inc/ScreenToCamera'),
setAngle: require('./inc/SetAngle'),
setBackgroundColor: require('./inc/SetBackgroundColor'),
setBounds: require('./inc/SetBounds'),
setName: require('./inc/SetName'),

View file

@ -0,0 +1,12 @@
var ScreenToCamera = function (x, y, pointOut)
{
this.matrix.transformPoint(x, y, pointOut);
// Add in the scroll offset
pointOut.x += this.scrollX;
pointOut.y += this.scrollY;
return pointOut;
};
module.exports = ScreenToCamera;

View file

@ -0,0 +1,12 @@
var DegToRad = require('../../../math/DegToRad');
var SetAngle = function (value)
{
if (value === undefined) { value = 0; }
this.rotation = DegToRad(value);
return this;
};
module.exports = SetAngle;

View file

@ -67,6 +67,13 @@ var Pointer = new Class({
this.justMoved = false;
},
positionToCamera: function (camera, output)
{
if (output === undefined) { output = { x: 0, y: 0 }; }
return camera.screenToCamera(this.position.x, this.position.y, output);
},
x: {
get: function ()

View file

@ -5,9 +5,8 @@ var PointWithinGameObject = require('./PointWithinGameObject');
// Array contains matching Game Objects.
// Array will be empty if no objects were matched.
var PointScreenToWorldHitTest = function (tempMatrix, x, y, gameObjectArray, camera, output)
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;
@ -21,17 +20,25 @@ var PointScreenToWorldHitTest = function (tempMatrix, x, y, gameObjectArray, cam
return output;
}
var screenPoint = camera.cameraToScreen({x: x, y: y});
var screenPoint = camera.cameraToScreen({ x: x, y: y });
var object;
var tpoint;
if (Array.isArray(gameObjectArray))
{
var culled = camera.cull(gameObjectArray);
var culledLength = culled.length;
for (var index = 0; index < culledLength; ++index)
for (var i = 0; i < culledLength; i++)
{
var object = culled[index];
var tpoint = GetTransformedPoint(tempMatrix, object, screenPoint.x + scrollX * object.scrollFactorX, screenPoint.y + scrollY * object.scrollFactorY);
object = culled[i];
tpoint = GetTransformedPoint(
tempMatrix,
object,
screenPoint.x + scrollX * object.scrollFactorX,
screenPoint.y + scrollY * object.scrollFactorY
);
if (PointWithinGameObject(object, tpoint.x, tpoint.y))
{
@ -41,9 +48,14 @@ var PointScreenToWorldHitTest = function (tempMatrix, x, y, gameObjectArray, cam
}
else
{
var object = gameObjectArray;
object = gameObjectArray;
var tpoint = GetTransformedPoint(tempMatrix, object, screenPoint.x + scrollX * object.scrollFactorX, screenPoint.y + scrollY * object.scrollFactorY);
tpoint = GetTransformedPoint(
tempMatrix,
object,
screenPoint.x + scrollX * object.scrollFactorX,
screenPoint.y + scrollY * object.scrollFactorY
);
if (PointWithinGameObject(object, tpoint.x, tpoint.y))
{

View file

@ -121,6 +121,15 @@ var SceneInputManager = new Class({
sortHandlerGO: require('./inc/SortHandlerGO'),
sortHandlerIO: require('./inc/SortHandlerIO'),
activePointer: {
get: function ()
{
return this.manager.activePointer;
}
},
// The x/y coordinates of the ActivePointer based on the first camera in the camera list.
// This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
x: {

View file

@ -3,6 +3,7 @@ var Class = require('../../utils/Class');
var Composite = require('./lib/body/Composite');
var Constraint = require('./lib/constraint/Constraint');
var Detector = require('./lib/collision/Detector');
var GetFastValue = require('../../utils/object/GetFastValue');
var Merge = require('../../utils/object/Merge');
var Sleeping = require('./lib/core/Sleeping');
var Vertices = require('./lib/geometry/Vertices');
@ -35,6 +36,19 @@ var PointerConstraint = new Class({
this.world = world;
var camera = GetFastValue(options, 'camera', null);
if (!camera)
{
this.camera = scene.sys.cameras.main;
}
else
{
this.camera = camera;
delete options.camera;
}
this.pointer = null;
this.active = true;
@ -109,7 +123,8 @@ var PointerConstraint = new Class({
}
else
{
var position = pointer.position;
// var position = this.camera.screenToCamera({ x: pointer.position.x, y: pointer.position.y });
var position = this.pointer.positionToCamera(this.camera);
if (constraint.bodyB)
{