The Mouse class doesn't support the following use case:
element I've specified when creating the Mouse instance.This is because the Mouse instance calls preventDefault on all mousewheel and DOMMouseScroll events. Additionally, it calls preventDefault on all other mouse and touch events: mousemove, mousedown, mouseup, touchmove, touchstart, and touchend.
For integrating a Matter.js scene into an environment with complex mouse interactions, it can be useful to leverage the Mouse class for sending interactions into the scene while integrating one's own interaction logic elsewhere.
My solution: ability to disable mousewheel listener entirely (since I didn't need scrolling in my physics interaction). So when I create my mouse instance I can disable the mousewheel event listener:
var mouse = Matter.Mouse.create(
myCanvasElement,
{
enabledEvents: {
mousewheel: false
}
}
);
Would you accept something like this?
https://github.com/colinsullivan/matter-js/commit/c5edfb243c1cb10a3ba696e876ca0061cf4d7b35
I think it should include options for disabling the other types of events too.
This has been raised before in #47 and as was mentioned there it's easy to just remove the event listeners in user code, something like:
mouse.element.removeEventListener("mousewheel", mouse.mousewheel);
mouse.element.removeEventListener("DOMMouseScroll", mouse.mousewheel);
It might be nice to have this functionality built in I guess, but I'm always a little reluctant to extend the features for non-physics parts of the codebase (I want to keep the project scope tight, see #65).
Most helpful comment
This has been raised before in #47 and as was mentioned there it's easy to just remove the event listeners in user code, something like:
It might be nice to have this functionality built in I guess, but I'm always a little reluctant to extend the features for non-physics parts of the codebase (I want to keep the project scope tight, see #65).