Slide left/right to move between scenes

Found a few solutions for slide left/right to swap between scenes but nothing seems perfect.

Currently am using the - put a rectangle on the screen with a alpha of 0 and capture the touch events etc… but that has stopped my over state on the buttons underneath from working. Also when your swiping you are pressing the buttons underneath, which isn’t brilliant on a soundboard app.

Is there a better way?

Also if I have a scrollview fullscreen on a scene would that matter or make it easier?

Thanks,

Dave

I think it depends on whether you want to allow the swipe to begin anywhere on the screen or only on a part which does not already respond to touch. Differentiating between objects which respond to taps and handling a touch are very separate, so that should not be a problem.

What I would suggest (strongly) is having the rect used to detect navigation swipes underneath all other touch-sensitive objects.

Secondly, if any object above the swipe detection layer handles touch events (rather than tap events) they should have a check for the direction and speed of the swipe. For example, if the swipe is left or right, and travels further than a given distance in less than a given amount of time (if you want) then it is a navigation swipe. If not, it is an interaction with the button (or whatever object.)

So I have the rectangle full screen as need the swipe from anywhere.

I have moved it the back of the group but then it doesn’t work?

Thanks,

Dave

Currently am using the - put a rectangle on the screen with a alpha of 0…

  1. You’d be better served using a newImageRect and an transparent texture.  i.e. Leave alpha at 1 and create a transparent texture in your text editor.
    Ex:  fillT.png

  2. What are you returning from your touch listener?  It should return false and you show also not allow any listeners to setFocus() or you’re lose the input to whatever object takes focus…

  3. If you try to do this with a scroller widget it won’t work easily.  The scroller will take focus and the rest of the touch events will go to the scroller.

  4. I have an example of swipe-composer-navigation here:

https://github.com/roaminggamer/RG_FreeStuff/tree/b68f5fce9934393f5b315f7c8b1d2882ee66eb2d/AskEd/2016/01/composerSwipeNavigation

You can simply download my whole ‘RG_FreeStuff’ git: https://github.com/roaminggamer/RG_FreeStuff

Then find the code here: ~/AskEd/2016/01/composerSwipeNavigation

https://www.youtube.com/watch?v=dZ8wfx2t4sQ

re: not working listeners … if you return true from a touch listener, the touch stops propagating.  Also, once a listener takes focus, future events in the sequence ONLY go to that listener.

Thanks for that, this is my swipe code -

local function startDrag(event) local swipeLength = math.abs(event.y - event.yStart) print(event.phase, swipeLength) local phase = event.phase if "began" == phase then return true elseif "ended" == phase or "cancelled" == phase then if event.yStart \> event.y and swipeLength \> 50 then composer.gotoScene("soundboard", {time=500, effect="slideUp"}) print("Swiped Left") elseif event.yStart \< event.y and swipeLength \> 50 then print( "Swiped Right" ) end end end

Still can’t get this working properly, tried the one above from romainggamer but can’t get that working at all and code looks to complicated to delve into.

Anyone else done this before?

Thanks,

Dave

What I do is have a runtime event for detecting swipes and individual objects have their own touch handlers.  I have a variable which I set to true if the runtime is handling the touch and false if object are handling the touch.  

So if the runtime is handling a swipe then the object touch handlers check the variable, don’t fire and simply return false to allow the runtime to carry on processing and visa versa.

This works well for me and the same setup could work for you?

I have the swipe working but the problem I have is the buttons play when you release your finger after the swipe.

As it’s a soundboard app, it’s annoying.

Thanks,

Dave

I think it depends on whether you want to allow the swipe to begin anywhere on the screen or only on a part which does not already respond to touch. Differentiating between objects which respond to taps and handling a touch are very separate, so that should not be a problem.

What I would suggest (strongly) is having the rect used to detect navigation swipes underneath all other touch-sensitive objects.

Secondly, if any object above the swipe detection layer handles touch events (rather than tap events) they should have a check for the direction and speed of the swipe. For example, if the swipe is left or right, and travels further than a given distance in less than a given amount of time (if you want) then it is a navigation swipe. If not, it is an interaction with the button (or whatever object.)

So I have the rectangle full screen as need the swipe from anywhere.

I have moved it the back of the group but then it doesn’t work?

Thanks,

Dave

Currently am using the - put a rectangle on the screen with a alpha of 0…

  1. You’d be better served using a newImageRect and an transparent texture.  i.e. Leave alpha at 1 and create a transparent texture in your text editor.
    Ex:  fillT.png

  2. What are you returning from your touch listener?  It should return false and you show also not allow any listeners to setFocus() or you’re lose the input to whatever object takes focus…

  3. If you try to do this with a scroller widget it won’t work easily.  The scroller will take focus and the rest of the touch events will go to the scroller.

  4. I have an example of swipe-composer-navigation here:

https://github.com/roaminggamer/RG_FreeStuff/tree/b68f5fce9934393f5b315f7c8b1d2882ee66eb2d/AskEd/2016/01/composerSwipeNavigation

You can simply download my whole ‘RG_FreeStuff’ git: https://github.com/roaminggamer/RG_FreeStuff

Then find the code here: ~/AskEd/2016/01/composerSwipeNavigation

https://www.youtube.com/watch?v=dZ8wfx2t4sQ

re: not working listeners … if you return true from a touch listener, the touch stops propagating.  Also, once a listener takes focus, future events in the sequence ONLY go to that listener.

Thanks for that, this is my swipe code -

local function startDrag(event) local swipeLength = math.abs(event.y - event.yStart) print(event.phase, swipeLength) local phase = event.phase if "began" == phase then return true elseif "ended" == phase or "cancelled" == phase then if event.yStart \> event.y and swipeLength \> 50 then composer.gotoScene("soundboard", {time=500, effect="slideUp"}) print("Swiped Left") elseif event.yStart \< event.y and swipeLength \> 50 then print( "Swiped Right" ) end end end

Still can’t get this working properly, tried the one above from romainggamer but can’t get that working at all and code looks to complicated to delve into.

Anyone else done this before?

Thanks,

Dave

What I do is have a runtime event for detecting swipes and individual objects have their own touch handlers.  I have a variable which I set to true if the runtime is handling the touch and false if object are handling the touch.  

So if the runtime is handling a swipe then the object touch handlers check the variable, don’t fire and simply return false to allow the runtime to carry on processing and visa versa.

This works well for me and the same setup could work for you?

I have the swipe working but the problem I have is the buttons play when you release your finger after the swipe.

As it’s a soundboard app, it’s annoying.

Thanks,

Dave