Closed jedeen closed 7 years ago
I am willing to implement this (I already have a working prototype I am using in game I am working on).
For handling the scenario's where the page could have a scroll bar, we could provide some sort of "enableMousewheelCapture" flag which uses event.preventDefault() to cancel the window from scrolling. That way, the developer can decide how to handle that circumstance.
Aside from that, what should I name the events? I am thinking "wheelforward" and "wheelbackward".
I like "wheelForward" and "wheelBackward". @excaliburjs/core-contributors, any thoughts?
Watching for changes in vertical scroll covers the most common action with a standard mousewheel. There are other scrolling scenarios we may want to address (for example, a trackball, or a mouse with sidescroll capability). Those are probably best left to a second issue to add additional support for changes in deltaX
and deltaZ
.
Looking into this further, we could be more generic and have a "wheel" event in general. Then leave it up to the develop to examine deltaX, deltaY, and deltaZ.
I started work on this about an hour ago, and that's the way I am going so far.
I will push up a draft shortly.
Also, side question: why var instead of let and const?
@jedeen Further issues.
According the MDN (https://developer.mozilla.org/en-US/docs/Web/Events/wheel) there is a "deltaMode" which defines what type of "detla" is pased. It can either be "pixels", "lines" or "pages".
The question is, do we try to normalize this, or do we just give the developer the deltaMode and let them deal with it?
I am leaning toward just giving the developer the deltaMode and letting them deal with it. In most use cases, developers are not even going to care about the raw values. They are just going to want to know if they were positive or negative.
Excalibur currently targets ECMAScript 5, which does not include the let
statement.
I think passing through the deltaMode
should be fine for now; we can always enhance the functionality at a later point.
@jedeen did you mean to leave this comment on the PR?
@kamranayub no, I haven't had a chance to look at the PR yet, just responding to the questions in the previous comment.
Context
Currently, Excalibur does not directly support wheel events (such as mouse scrolling) for input.
Proposal
Add support for wheel events.
Additionally, work will need to be done for the scenario where a game is using wheel events, but the page has a scroll bar.