Request for click event
This is a request for a click event that functions like click events do in html requiring that the mousedown and subsequent mouseup occur on the same element. If you mousedown on a link and then move the cursor off it before releasing, the click does not fire. If you mousdown somewhere and move your cursor over a link and mouseup the click event does not fire. It's mobile version, tap would be nice as well.
Also consider double click and double tap.
To get click events working, it's also necessary to track mouseenter and mouseleave events. These are kind of tricky, as they need to piggyback on the mousemove event, and click needs to piggyback on the mouseenter and mouseleave events.
FYI, I don't want melonJS to emulate the weirdness of the mouseover and mouseout events. See this article for rationalization: http://www.quirksmode.org/js/events_mouse.html
Summary of new events requested:
tapdoubletapclickdoubleclickmouseentermouseleave
Add a hover/mouseover to the list.
"The hover method binds handlers for both mouseenter and mouseleave events. You can use it to simply apply behavior to an element during the time the mouse is within the element."
https://groups.google.com/forum/?fromgroups=#!topic/melonjs/zqaWt2WLYzs
When click is added, the GUI_Object's "onclicked" event should be updated to use it, and that event should probably be renamed onclick().
Registering mouse events should probably have two more options, propagateToDom and propagateZ, the latter determining if a mouse event fires only the top most effected object or not.
me.input.registerMouseEvent('click', this.collisionBox, this.onMouseDown.bind(this), true, false);
I think mousemove may be the only mouse event that wouldn't need the propagateZ option.
Meh, maybe propagate to DOM isn't needed and isn't the accurate term anyway, and we just don't ever cancel out DOM events. The user can unbind DOM events if they want. I unbound the spacebar event because its the first thing I try in a game to jump with and Firefox makes the whole screen scroll when you hit the spacebar.
Add a hover/mouseover to the list.
@greghouston mouseenter is mouseover. Only with less stupid. :)
Ideas for how event propagation should be handled belong in Ticket #118
Like click is a combination of mousedown and mouseup (but with extra logic), mouseover is a combination of mouseenter and mouseleave, though not nearly as complex. It may be easier to not deal with mouseover since it is simple enough to just define mouseenter and mouseleave events. All mouseover is is a shorthand for that combination. Click on the other hand is not so trivial and shouldn't be left up to the user to get to function.
@greghouston mouseover is the same as mouseenter except mouseover causes superfluous events to be fired with nested objects. Likewise, mouseout is the same as mouseleave except it also causes superfluous events to be fired. Have a look at the following articles.
http://www.quirksmode.org/js/events_mouse.html https://developer.mozilla.org/en-US/docs/DOM/DOM_event_reference/mouseenter http://msdn.microsoft.com/en-us/library/bb979811(v=vs.95).aspx
Meh, was using the wrong term for hover. Hover is the combination of mouseenter and mouseleave.
Ah. Hover is just a convenience method that provides two different callbacks; one for mouseenter and one for mouseleave.
Calling
$(selector).hover(handlerIn, handlerOut)is shorthand for:$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
Or optionally, one callback for both events; i.e. $(selector).hover(handlerInOut) is shorthand for $(selector).mouseenter(handlerInOut).mouseleave(handlerInOut)
IMHO, it only provides syntactic sugar.
In my opinion, we do not want/need to implement so much additional events like click, doubleclick (or tap/doubletap) in melonJS.
Click is basically triggered based on a mousedown event following by a mouseup event on the same object (For tap, it’s touchstart+touchend), and providing only the “base” object allow anyone to add any specific behavior (e.g. different graphic on mousedown and mouseup) and “simulate” the required event, while not overloading the engine with tons of events to listen to.
Mouse Hover and Drag & Drop features are however nice and very useful additions
Click is easily by far the most commonly used mouse event in HTML applications. I think it would be a huge mistake not to include it. Second place probably goes to hover which also requires mousenter and mouseleave.
On Tue, Sep 25, 2012 at 9:42 PM, obiot [email protected] wrote:
In my opinion, we do not want/need to implement so much additional event like click, doubleclick (or tap/doubletap) in melonJS.
Click is basically triggered based on a mousedown event following by a mouseup event on the same object (For tap, it’s touchstart+touchend), and providing only the “base” object allow anyone to add any specific behavior (e.g. different graphic on mousedown and mouseup) and “simulate” the required event, while not overloading the engine with tons of events to listen to.
Mouse Hover and Drag & Drop features are however nice and very useful additions
— Reply to this email directly or view it on GitHubhttps://github.com/obiot/melonJS/issues/115#issuecomment-8877250.
Mouse events supported by KinectJS for instance:
KineticJS supports mouseover, mousemove, mouseout, mousedown, mouseup, click, dblclick, touchstart, touchmove, touchend, dbltap, dragstart, dragmove, and dragend
I intend to use drag to move the viewport in my game (like Tower Madness and Fieldrunners) so will eventually make a request for it as well. In my opinion, supporting basic mouse events is much more important than supporting menu screens, making special functions for things like collectable items, blinking objects, etc. Mouse events are foundational.
Working with mouse events is one of the two things that has caused me the most frustration while working with melonjs in its current state. Having solid mouse event support will go a long ways in making the melonjs easy to use, and something programmers will recommend to other programmers.
FWIW, I built my first melonJS game without even considering mouse support. So I cannot agree that any mouse event is "foundational".
Your game uses old school keyboard commands. How would you play it on an iPod, iPhone or iPad? As soon as you try to make a fully functional cross-platform, keyboardless game you need solid mouse support as a foundation.
and touch support obviously.
I wouldn't. And that's quite my point; a feature should not be considered foundational unless it is required in all cases. Like, say, drawing to a canvas is foundational. Or basic audio support is foundational. Any input at all is foundational.
But drawing rotated sprites to a canvas are not foundational. MIDI audio support is not foundational. And mouse events are not foundational. These are nice features to have, and some wonderful things can be created based upon them. But support or lack thereof will not define melonJS.
Mouse-click and mouse-over support would be fantastic. To provide an example use-case; the goal on http://nurph-staging.herokuapp.com/ is to enable the player to hover-over & click-on entities to fire events (such as opening dialog boxes), and to navigate the map using the mouse cursor as well as with the keyboard arrows.
Summary of new events requested:
tapdoubletapclickdoubleclickmouseentermouseleave
plus
mousedown
mouseup
mousedown & mouseup are already supported (together with touchstart & touchend)