Ways to force any touch events to end when app suspends?

I’ve noticed a bug on one of my in game objects, and wonder if anyone has a good workaround for it?

If the user has their finger on a touchable object and is moving around, and the presses the home button to background the app, when they resume the object is frozen because an “ended” phase was never received for the object.

Is there a way to force all touch events to end? So that on suspend you can force the app to think that all touches have been removed, and so call the “ended” phase in all touch listeners?

My apps don’t exhibit this behavior. Are you encountering this on iOS or Android?

iOS for definite, not sure on Android.

I should add that my touch events have some bools that get set to true/false when the touch begins/ends, so that certain items can only respond to a single touch.  

The problem is that because the touch hasn’t left the screen, and then the app goes into the background, the “ended” phase never gets called, and so my own bool never gets reset.

So it’s not a Corona bug as such, but at the same time the touch event not ending could do with some kind of workaround too.

You could always stick in a listener to your gameloop that, when the app gets suspended, it resets your bool to the original value. Maybe I’m oversimplifying it, but this is what I do when I have a boolean that needs to be reset from another stimulus. 

Here’s some documentation on suspend listeners:

https://docs.coronalabs.com/api/event/system/type.html

http://forums.coronalabs.com/topic/43082-discussion-on-application-suspendresume-exit-system-events/#entry224381

The other thing you could do, theoretically, is to test for event.phase == “cancelled” as well; you’d think one of that or “ended” would be called during a suspend event.

I believe @richard9 is correct: “cancelled” should be triggered by the system when the app is suspended. If you’re seeing otherwise, then I can investigate more.

Best regards,

Brent

I didn’t notice that I was already checking for the “cancelled” phase on another object,  which is why that second object didn’t exhibit the same behaviour.

So you’re absolutely right, and I feel like quite the dunce  :wacko:

Thanks guys.

My apps don’t exhibit this behavior. Are you encountering this on iOS or Android?

iOS for definite, not sure on Android.

I should add that my touch events have some bools that get set to true/false when the touch begins/ends, so that certain items can only respond to a single touch.  

The problem is that because the touch hasn’t left the screen, and then the app goes into the background, the “ended” phase never gets called, and so my own bool never gets reset.

So it’s not a Corona bug as such, but at the same time the touch event not ending could do with some kind of workaround too.

You could always stick in a listener to your gameloop that, when the app gets suspended, it resets your bool to the original value. Maybe I’m oversimplifying it, but this is what I do when I have a boolean that needs to be reset from another stimulus. 

Here’s some documentation on suspend listeners:

https://docs.coronalabs.com/api/event/system/type.html

http://forums.coronalabs.com/topic/43082-discussion-on-application-suspendresume-exit-system-events/#entry224381

The other thing you could do, theoretically, is to test for event.phase == “cancelled” as well; you’d think one of that or “ended” would be called during a suspend event.

I believe @richard9 is correct: “cancelled” should be triggered by the system when the app is suspended. If you’re seeing otherwise, then I can investigate more.

Best regards,

Brent

I didn’t notice that I was already checking for the “cancelled” phase on another object,  which is why that second object didn’t exhibit the same behaviour.

So you’re absolutely right, and I feel like quite the dunce  :wacko:

Thanks guys.