From d6829bf536533ce9a747038fa28255dd12bc3889 Mon Sep 17 00:00:00 2001 From: liabru Date: Sun, 8 Feb 2015 00:16:12 +0000 Subject: [PATCH] added support for compound bodies in MouseConstraint --- src/constraint/MouseConstraint.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/constraint/MouseConstraint.js b/src/constraint/MouseConstraint.js index e0072ad..99695c4 100644 --- a/src/constraint/MouseConstraint.js +++ b/src/constraint/MouseConstraint.js @@ -84,16 +84,21 @@ var MouseConstraint = {}; for (var i = 0; i < bodies.length; i++) { body = bodies[i]; if (Bounds.contains(body.bounds, mouse.position) - && Vertices.contains(body.vertices, mouse.position) && Detector.canCollide(body.collisionFilter, mouseConstraint.collisionFilter)) { - - 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; + 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; - Sleeping.set(body, false); - Events.trigger(mouseConstraint, 'startdrag', { mouse: mouse, body: body }); + Sleeping.set(body, false); + Events.trigger(mouseConstraint, 'startdrag', { mouse: mouse, body: body }); + + break; + } + } } } } else {