I am working off the Slingshot demo. The problem is that after the rock is fired, it can still be clicked on and dragged around, which I want to disable.
I've added a filter to the rock:
var rockOptions = {
density: 0.004,
restitution: 0.75,
collisionFilter: { mask: SOLID, category: NEXTBALL }
};
And to the mouseconstraint:
var mouse = Mouse.create(render.canvas),
mouseConstraint = MouseConstraint.create(engine, {
mouse: mouse,
collisionFilter: { category: NEXTBALL },
constraint: {
stiffness: 0.2,
render: {
visible: true
}
}
});
And then in the click event I attempt to change that filter, so it should no longer match the mouses category:
Events.on(engine, "afterUpdate", function () {
if (
mouseConstraint.mouse.button === -1 &&
(rock.position.x > shootPosition.x + 20 ||
rock.position.y < shootPosition.y - 20)
) {
Composite.remove(engine.world, elastic);
rock.collisionFilter = {category: SOLID, mask: SOLID};
}
});
But it still is draggable. I'm guessing the problem is how I'm changing the filter on the rock, but I don't see anything in the docs to suggest a way to change it.
I don't think it's because of the categories I've set up, but here they are just in case (the solid and image ones do work, the ball doesn't collide with image ones:
const SOLID = 0x0001;
const IMAGE = 0x0002;
const NEXTBALL = 0x0003;
Help me make the rock stop being clickable