mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-13 16:18:50 -05:00
added support for compound bodies in MouseConstraint
This commit is contained in:
parent
87f90655b7
commit
d6829bf536
1 changed files with 13 additions and 8 deletions
|
@ -84,16 +84,21 @@ var MouseConstraint = {};
|
||||||
for (var i = 0; i < bodies.length; i++) {
|
for (var i = 0; i < bodies.length; i++) {
|
||||||
body = bodies[i];
|
body = bodies[i];
|
||||||
if (Bounds.contains(body.bounds, mouse.position)
|
if (Bounds.contains(body.bounds, mouse.position)
|
||||||
&& Vertices.contains(body.vertices, mouse.position)
|
|
||||||
&& Detector.canCollide(body.collisionFilter, mouseConstraint.collisionFilter)) {
|
&& Detector.canCollide(body.collisionFilter, mouseConstraint.collisionFilter)) {
|
||||||
|
for (var j = body.parts.length > 1 ? 1 : 0; j < body.parts.length; j++) {
|
||||||
|
var part = body.parts[j];
|
||||||
|
if (Vertices.contains(part.vertices, mouse.position)) {
|
||||||
|
constraint.pointA = mouse.position;
|
||||||
|
constraint.bodyB = mouseConstraint.body = body;
|
||||||
|
constraint.pointB = { x: mouse.position.x - body.position.x, y: mouse.position.y - body.position.y };
|
||||||
|
constraint.angleB = body.angle;
|
||||||
|
|
||||||
constraint.pointA = mouse.position;
|
Sleeping.set(body, false);
|
||||||
constraint.bodyB = mouseConstraint.body = body;
|
Events.trigger(mouseConstraint, 'startdrag', { mouse: mouse, body: body });
|
||||||
constraint.pointB = { x: mouse.position.x - body.position.x, y: mouse.position.y - body.position.y };
|
|
||||||
constraint.angleB = body.angle;
|
|
||||||
|
|
||||||
Sleeping.set(body, false);
|
break;
|
||||||
Events.trigger(mouseConstraint, 'startdrag', { mouse: mouse, body: body });
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue