diff --git a/v3/src/camera/2d/Camera.js b/v3/src/camera/2d/Camera.js index 8cbbcc068..088642a5e 100644 --- a/v3/src/camera/2d/Camera.js +++ b/v3/src/camera/2d/Camera.js @@ -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'), diff --git a/v3/src/camera/2d/inc/ScreenToCamera.js b/v3/src/camera/2d/inc/ScreenToCamera.js new file mode 100644 index 000000000..8017402fc --- /dev/null +++ b/v3/src/camera/2d/inc/ScreenToCamera.js @@ -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; diff --git a/v3/src/camera/2d/inc/SetAngle.js b/v3/src/camera/2d/inc/SetAngle.js new file mode 100644 index 000000000..4bea56fe6 --- /dev/null +++ b/v3/src/camera/2d/inc/SetAngle.js @@ -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; diff --git a/v3/src/input/Pointer.js b/v3/src/input/Pointer.js index 6e2f09a94..1906b97c6 100644 --- a/v3/src/input/Pointer.js +++ b/v3/src/input/Pointer.js @@ -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 () diff --git a/v3/src/input/global/inc/PointScreenToWorldHitTest.js b/v3/src/input/global/inc/PointScreenToWorldHitTest.js index 4bd283653..dfdb7eeb7 100644 --- a/v3/src/input/global/inc/PointScreenToWorldHitTest.js +++ b/v3/src/input/global/inc/PointScreenToWorldHitTest.js @@ -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)) { diff --git a/v3/src/input/local/SceneInputManager.js b/v3/src/input/local/SceneInputManager.js index 4ff1888d5..f1fbf1a70 100644 --- a/v3/src/input/local/SceneInputManager.js +++ b/v3/src/input/local/SceneInputManager.js @@ -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: { diff --git a/v3/src/physics/matter-js/PointerConstraint.js b/v3/src/physics/matter-js/PointerConstraint.js index e748b3489..a0f88f2b5 100644 --- a/v3/src/physics/matter-js/PointerConstraint.js +++ b/v3/src/physics/matter-js/PointerConstraint.js @@ -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) {