Problem with swipe gesture: event data is passed between scenes, immediately causing another swipe

Hello,

I have a question concerning touches and scene transitions.

My aim is to code a swipe between a row of scenes, using touches on a scrollView in composer: A touch is detected, and as it moves horizontally more than an limit, composer will go to the next (or previous) scene.

This works well so far, a s long as the scene transition starts at the “ended” phase of the touch. 

But if the scene transition starts at touch phase = “move”, the swipe script in the upcoming scene is fired as well, immediately causing another swipe – and so on. It seems that the event data of the first touch is passed to or still available for the following scene, though the touch event listener ends with  return true.

Any idea of what has to be done, so that a scene transition can be activated during a touch move?

Thanks for help!

Hi @orangecyan,

Practically speaking, a “swipe” actually should have an “ended” phase… that means the user actually lifted their finger off the screen, thus completing the swipe motion. If they don’t, then it’s just one continuous drag motion with a beginning but no end.

Now, if you actually don’t care that it’s a “swipe” versus a “continuous drag”, you can probably code it to work. Consider keeping a variable that Composer recognizes across all scenes, and that variable tracks the current x position of the touch swipe/drag that is in process. I imagine it’s basically the same variable that you’re using to determine how far the user must drag before switching scenes… the main difference is, when you change scenes, update the variable to the current x position, then compare when the user has dragged another number of pixels.

Hope this helps,

Brent

Hi Brent,

thanks for the very quick reply! And your ideas were very helpful!

I made some more experiments: There really is a continuous drag and a continuous move event over scene changes, and in the upcoming scene the event listener immediately reacts to these move events with the event data of the previous scene. That’s why there is a chain of swipe events following up, as long as there is no touch ended event.

Solution: Just before leaving a scene, I put the delta x position of the touch move into a variable that’s available across scenes, like your idea. In the next scene (basically in all swipe scenes), this variable is added to event.xStart. And at touch ended, this variable is set to zero again. So, at a new scene, there won’t be an immediate swipe any more.

Thanks a lot again!

You are a great team at Corona.

Simon

Hi @orangecyan,

Practically speaking, a “swipe” actually should have an “ended” phase… that means the user actually lifted their finger off the screen, thus completing the swipe motion. If they don’t, then it’s just one continuous drag motion with a beginning but no end.

Now, if you actually don’t care that it’s a “swipe” versus a “continuous drag”, you can probably code it to work. Consider keeping a variable that Composer recognizes across all scenes, and that variable tracks the current x position of the touch swipe/drag that is in process. I imagine it’s basically the same variable that you’re using to determine how far the user must drag before switching scenes… the main difference is, when you change scenes, update the variable to the current x position, then compare when the user has dragged another number of pixels.

Hope this helps,

Brent

Hi Brent,

thanks for the very quick reply! And your ideas were very helpful!

I made some more experiments: There really is a continuous drag and a continuous move event over scene changes, and in the upcoming scene the event listener immediately reacts to these move events with the event data of the previous scene. That’s why there is a chain of swipe events following up, as long as there is no touch ended event.

Solution: Just before leaving a scene, I put the delta x position of the touch move into a variable that’s available across scenes, like your idea. In the next scene (basically in all swipe scenes), this variable is added to event.xStart. And at touch ended, this variable is set to zero again. So, at a new scene, there won’t be an immediate swipe any more.

Thanks a lot again!

You are a great team at Corona.

Simon