Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Mouse vs Touches events — Gideros Forum

Mouse vs Touches events

CarolineCaroline Guru
edited January 2012 in General questions
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?
+1 -1 (+2 / -0 )Share on Facebook

Comments

  • I has ask myself them same question but then I use only touch events because I test mostly on the device.
  • atilimatilim Maintainer
    If you're creating a single-touch application, using mouse events has two advantages:
    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'm hoping that one day Gideros will work on the desktop as well as devices, so I guess it would be better to get used to using Mouse events.
  • gorkemgorkem Maintainer
    Yes, that's in the roadmap, too (for both Mac OS X & MS Windows - and maybe Linux).
  • Sorry for posting on an older thread, but I don't want to start new threads if I can help it - better to keep things together I think.

    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

    +1 -1 (+1 / -0 )Share on Facebook
  • atilimatilim Maintainer
    Hi @moopf,

    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
  • Hi @atilim,

    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 :D
  • atilimatilim Maintainer
    Thank you :)

    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.
    +1 -1 (+2 / -0 )Share on Facebook
  • Quick question

    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?
  • Hi @ar2rsawseen, on iOS I believe that's the case, at least from what I've seen. However, I've spent some time this afternoon working out why my touch events weren't behaving nicely on my android tablet and I'm pretty sure that I found by accident that touch move was firing continuously. In fact, there was some other weirdness with android touches as well, but I couldn't quite put my finger on them (forgive the pun) - but did work around them with some extra checks and balances.

    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.
  • atilimatilim Maintainer

    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?
    Exactly. currently there is no way to dispatch mouse event without pressing the button and most probably it won't until we introduce the desktop applications.

    And on iOS and Android, first touch is dispatched as mouse event.
  • Sorry for bringing up this older thread but I too am confused about touch events and mouse events. I'm working on an app that has multi touch - do I just use touch events?

    Mouse events seem to work on both the computer and on the device, so not sure what the difference is?
  • @Tom2012 there was a difference, but since Gideros (I think) 2012.9 version, there is a compatability so both work on both.

    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 :)
Sign In or Register to comment.