How to detect entering multiple objects on touch/drag correctly

I have a display object that when touched, displays several other objects. If the user ends the touch all objects need to disappear but if they continue to touch and drag into one of the other objects it should highlight.

Is there a “correct” to detect entering and exiting the secondary objects while the touch is still occurring or do I need to iterate through every object during the move event looking for intersection?

I just dont see how I get the ended phase if the user drags out the initial object and lets go on one of my selected objects. I need this so I can clear secondary object when they release no matter where they are on the screen. [import]uid: 111413 topic_id: 26919 reply_id: 326919[/import]

You’d need to do it manually I think while the first touch event is still active (IE on the “moved” phase). Luckily I have posted some collision routines to help :slight_smile:

http://developer.anscamobile.com/forum/2012/05/28/some-lua-collision-detection-code-you-all [import]uid: 46639 topic_id: 26919 reply_id: 109316[/import]

Can you just sense the “ended” phase on any secondary object? You must already be applying listeners to them, if they are intended to highlight on the “began” or “moved” phase. Thus, you could just sense any “ended” phase on any secondary object, and call a function to deselect everything.

If the deselect needs to occur on the touch ending ANYWHERE on the the screen (not necessarily over an object), my approach would be to have an overlaying invisible sensory rectangle that covers the entire screen. Use this to provide the ended phase, not the individual objects.

Does this help? Perhaps I’m not understanding your exact scenario.

Brent Sorrentino

[import]uid: 9747 topic_id: 26919 reply_id: 109322[/import]

I did see your collision code and was already using it. Thank you! [import]uid: 111413 topic_id: 26919 reply_id: 109352[/import]

Brent,

To sense the ended event on the secondary objects I have to set focus, this means the original object loses ended event and so if the user lets go when not on top of any object I don’t know it.

I think your idea of an invisible box around them and then just using intersection detection may be the easiest solution.

I’m also thinking of using tap instead of touch. I think it may be just as natural and less complicated.

Tap to open menu, tap to close menu. [import]uid: 111413 topic_id: 26919 reply_id: 109353[/import]

Hi again,

Personally, I never use “setFocus”. This isn’t to say it’s bad or unnecessary, I’ve just had better luck using other methods to control my sensory inputs and what can receive/return them.

If these are basic touch/tap interactions, I’m confused why you’d need to program some custom “collision intersection detection” function(s). Again, maybe I’m not understanding exactly what your scenario is… can you provide a more detailed explanation?

“Tap” is definitely very useful, and often easier than “touch”, but of course it’s also more limited. Really depends what you need to accomplish. :slight_smile:

Brent Sorrentino
[import]uid: 9747 topic_id: 26919 reply_id: 109383[/import]

So I have object A. When Tapped, it displays objects B,C,D. If any of those are tapped I am done and B,C,D objects are removed. This is easy. However if after tapping object A, the background is tapped/touched I want to also remove B,C,D

In addition if object A is dragged on instead of tap I want to have a different behavior but the touch events seems to process before the tap. [import]uid: 111413 topic_id: 26919 reply_id: 109387[/import]

OK, this is a unique scenario but certainly possible. :slight_smile:

I would definitely abstain from putting both a “tap” AND “touch” listener on object A. This is redundant and might create problems. Anyway, if you need object A to have both tap and “drag” behavior, you need a touch listener for that.

What I would do is this:

  1. Object A has a boolean flag “isTap” or something.
  2. On the “began” phase of this touch, you set “isTap = true”
  3. On the “moved” phase of this object, you set “isTap = false”… this basically tells Corona, it’s no longer a TAP because the user moved/dragged, and by definition a TAP is a down/up touch in the *same* location on the screen.
  4. The “moved” phase could also be used for your “drag” functionality on object A
  5. On the “ended” phase of object A, you check if “isTap” is true or not. If TRUE, then you know it was a tap motion (although not technically a tap, just a touch listener behaving like a tap!).

Objects B,C,D, etc. can just have tap listeners; no need to do complex touch sensing on these.

Additionally, an overlay screen sensor will perform the “cancel all” functionality that you need. Just be sure to place it BEHIND the other objects, and include “return true” in the touch listener function of object A, so the touch doesn’t transmit *through* this object to the screen sensing rectangle.

Maybe this all seems like overkill, but give it a try and see how it goes.

Brent Sorrentino [import]uid: 9747 topic_id: 26919 reply_id: 109391[/import]

Brent, this works. It seems like it should be easier than this but it works fine.

Thank you.

Scott [import]uid: 111413 topic_id: 26919 reply_id: 109393[/import]