I'm confused as to why both Mouse and Touch events are necessary, and what the difference is, and whether to put my code in Mouse or Touches event.
I'm making a slider, using the Gideros Button code as a basis.
I want to both position the slider button horizontally, and return a slider value, in either onMouseMove or onTouchesMove, but I'm not sure which.
I understand that the onTouchesMove will not be performed if I run the code in the simulator, and that on the device both onMouseMove and onTouchesMove will be performed.
So it seems that it would be better to use onMouseMove, as in the Gideros Drag Me example, but why would I ever want to put code in onTouchesMove? Is it only for multi-touch, as your manual says "Mouse events are mainly used in single-touch whereas touch events are used in multi-touch applications."
If I only ever have one-finger-touches in an app, would I only ever use onMouseMove?
Comments
1. It also works in desktop player
2. It's simpler to work with
On the other hand, as Mike, you can totally ignore mouse events and work only with touch events even if you're developing a single-touch application.
I've got a little issue on touch/mouse events. I'm basically trying to use the mouse events wherever I don't need multitouch so that when desktop distribution is available I don't need to revisit the code. But this creates a little problem. In my scene tree I have a main parent that can be multi-touched to zoom and pan the play area, plus can be tapped to move a sprite to the touch position.
In a child sprite I'm detecting mouse events directly for some interaction but, of course, event:stopPropagation() won't actually stop the touch event on the parent from being fired as well, which is causing an unwanted second action to take place.
Is there any way to do a kind of "stop propagation for both touch and mouse versions of the event", e.g. if I'm in a listener for MOUSE_DOWN, I'd like to stop the TOUCHES_BEGIN event from firing as well if my code decides that it wants to stop propagation.
I can certainly rig up some code to add my own stop facility but I'm just wondering if there's already a way that I'm missing of stopping the equivalent mouse/touch event firing.
As an aside, is there any particular reason why there is a separate mouse event at all? On desktops couldn't you just fire off a single touch for a mouse click? What was the design decision behind this (I'm just curious!)
Likes: papirosnik
Unfortunately, there is no easy way to stop propagation of mouse/touch events at the same time. For example, in Button example, to stop the propagation, touch events are handled separately.
At the beginning, I was thinking that if someone wants to develop a single-touch application then he/she uses mouse events and otherwise he/she uses touch events. On the other hand, I start to think that providing a separate mouse event was a design mistake.
To overcome this mistake, these steps seem reasonable to me:
1. Let the desktop player (and applications) also dispatch touch events
2. Put a flag to enable/disable multitouch
3. To ensure backward compatibility, leave mouse events as it is
4. Optionally, change all examples from mouse events to touch events
That's no problem I can code accordingly now I know there's no easy, built-in way I'll most likely ditch mouse events completely and stick to touch events.
I think your steps are reasonable. If you can bring everything into one type of event, regardless of whether it's a finger or a mouse click, then I think it would be much easier for people to deal with these events. I've been trying to use mouse events as much as possible (even though I don't want to!) simply because I felt that this was the only way to ensure events would fire when we came to desktop distribution. I'd much prefer just to deal with touches.
Just for my own curiosity, do you have any rough idea when desktop distribution would be available anyway? If you don't know, that's fine, I'm just curious whether it would be months or a year+ away.
Again, thank you for your reply. The help and explanation here is awesome
For the desktop distribution, I want to say in months but I cannot Currently, some other features (admob, iAd, IAP and android plugins) have higher priority than desktop distribution.
Likes: MikeHart, ar2rsawseen
Right now I'm testing mouse move event on player, and it seems to fire only when I hold mouse button down and move it.
I can't test it on device right now, but I suppose that well you kind of can't move without touching screen thus mouse move event fires when moving finger, am I right?
I simply trying to recreate onmouseover event. Is there anything additional I should know?
This might be the same for mouse move, it might not, I'm not using those events now after this thread - but it might be worth checking.
And on iOS and Android, first touch is dispatched as mouse event.
Mouse events seem to work on both the computer and on the device, so not sure what the difference is?
Use mouse when you need to have an ability to provide only one touch (and lock all other screen from other touches)
And use touch events when you need on or many touches