I have some code like the following for the matter.js library:
// create two boxes and a ground
var boxA = Bodies.rectangle(400, 200, 80, 80);
var boxB = Bodies.rectangle(450, 50, 80, 80);
var ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
// add all of the bodies to the world
World.add(engine.world, [boxA, boxB, ground]);
Events.on(engine, 'tick', function(event) {
if (mouseConstraint.mouse.button == 0){
alert("what is clicked?");
}
});
Is there a way I can tell if boxA
or boxB
has been clicked with the mouse in the event handler?