Ok so I finally got the mouse events to trigger in the console. I can now report back that I can observe mouse state. The next step is to get the body from the mouseConstraint.
Here’s the mouseconstraint code that’s working for me:
// - - - - - - - - - - - - - - - - -
// Sets up mouse constraints
// - - - - - - - - - - - - - - - - -
var mouseConstraint = Matter.MouseConstraint.create(engine, {
element: canvas,
constraint: {
render: {
visible: false
},
stiffness: 0.8
}
});
Matter.World.add(world, mouseConstraint);
Matter.Events.on(mouseConstraint, 'mousedown', function (event) {
console.log("mousedown called");
var mousePosition = event.mouse.position;
mp = mousePosition;
mouseIsDown = true;
});
Matter.Events.on(mouseConstraint, 'mouseup', function (event) {
console.log("mouseup called");
var mousePosition = event.mouse.position;
mp = mousePosition;
mouseIsDown = false;
});