Skip to content

Commit e194b95

Browse files
committed
PointerConstraint now takes the scene camera it should use as a config option.
1 parent d9a9c7a commit e194b95

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

v3/src/physics/matter-js/PointerConstraint.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var Class = require('../../utils/Class');
33
var Composite = require('./lib/body/Composite');
44
var Constraint = require('./lib/constraint/Constraint');
55
var Detector = require('./lib/collision/Detector');
6+
var GetFastValue = require('../../utils/object/GetFastValue');
67
var Merge = require('../../utils/object/Merge');
78
var Sleeping = require('./lib/core/Sleeping');
89
var Vertices = require('./lib/geometry/Vertices');
@@ -35,6 +36,19 @@ var PointerConstraint = new Class({
3536

3637
this.world = world;
3738

39+
var camera = GetFastValue(options, 'camera', null);
40+
41+
if (!camera)
42+
{
43+
this.camera = scene.sys.cameras.main;
44+
}
45+
else
46+
{
47+
this.camera = camera;
48+
49+
delete options.camera;
50+
}
51+
3852
this.pointer = null;
3953

4054
this.active = true;
@@ -109,7 +123,8 @@ var PointerConstraint = new Class({
109123
}
110124
else
111125
{
112-
var position = pointer.position;
126+
// var position = this.camera.screenToCamera({ x: pointer.position.x, y: pointer.position.y });
127+
var position = this.pointer.positionToCamera(this.camera);
113128

114129
if (constraint.bodyB)
115130
{

0 commit comments

Comments
 (0)