Stop Runtime touch event from triggering when tapping button

I have a touch event on the runtime object that controls gameplay, but now I want to add a pause button. The button works with a simple tap event, but this also runs the touch event on the runtime object.

Is there a way to stop the runtime event from detecting touches when the intent is to press a button?

Figured it out. I’m using the tap event for the pause button, and touch event for the runtime object. Touch propagation is not shared between events.

I fixed this by adding a touch event listener to the pause button that does nothing except prevent propagation:

pausebutton:addEventListener("touch", function() return true end)
1 Like

It’s generally safer to just use touch events everywhere and avoid tap events altogether.

The main difference between a tap and a touch event is that a tap event does not have event phases and can easily get cancelled. When you touch the screen/press the mouse key, a touch event begins. When you let go, the same touch event ends.

If you move your finger/cursor even 1px while holding down, the touch event will trigger a moved phase, but a tap event will cancel itself. In other words, touch events are a lot more reliable and then you don’t need to worry about the events propagating like that.

3 Likes

One noticeable exception to this “rule” is when you have objects in a scrollView or tableView. You will get a began event but then the scrollView or tableView will take over. I know you can setFocus, but normally tap events are just easier in this use case.

1 Like

Yes, but that’s a different thing.

You can freely decide when and how to pass focus from the objects to the scrollView/tableView by adding a few lines of code. You can make it as strict as tap events, i.e. 0 pixels of movement allowed, or you can allow for a bit of movement before passing the focus.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.