excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.83k stars 192 forks source link

Add support for wheel events #808

Closed jedeen closed 7 years ago

jedeen commented 7 years ago

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.

mrkmg commented 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".

jedeen commented 7 years ago

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.

mrkmg commented 7 years ago

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?

mrkmg commented 7 years ago

@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.

jedeen commented 7 years ago

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.

kamranayub commented 7 years ago

@jedeen did you mean to leave this comment on the PR?

jedeen commented 7 years ago

@kamranayub no, I haven't had a chance to look at the PR yet, just responding to the questions in the previous comment.