@jkrassman,
Sorry! I subscribed to this thread, but didn’t see the update e-mail.
I’ve looked over your original question again and your latest update and have some questions and suggestions.
Originally you said you have two buttons (left and right) for navigation.
1. Are you still using these buttons in your game/app?
2. Are you you also supporting a swipe functionality?
I will assume that the answers to questions #1 and #2 are “Yes” and that you want two pushbuttons and a swipe function that do similar things.
With the above assumption in mind, you need to do a few things.
-
Forget about dispatch. I think you’ll be better off with direct function calls.
-
Make copies of your original code and set that code aside.
-
Gut your original callback(s) for left and right button pushes. That is remove all of the code that does utility work like updating your game logic, creating/destroying/modifying display objects, etc.
-
Take the utility code you removed and put it one or more new utility functions. It is OK to pass the event table to these functions if they need something from the table to do their work.
-
Take the gutted callback(s) from step #2 and insert calls to your utility code from step #3.
-
Substitute the new callback(s) for your old callback(s).
-
Test the changes and be sure you didn’t break anything.
-
Write a new callback for the swipe event. This callback should only make decisions about the swipe. In the appropriate places, call the extracted utility code from step #3.
-
Hook up your new swipe callback and test it out.
The following is a purely hypothetical example of what I just layed out in the steps above.
My hypothetical original button code
left\_touch = function( event )
if event.phase == "began" then
-- LEFT WORK A
elseif event.phase == "moved" then
-- LEFT WORK B
elseif event.phase == "ended" or event.phase == "cancelled" then
-- LEFT WORK C
end
-- LEFT WORK D
end
leftButton:addEventListener("touch",left\_touch)
-- Assume similar for right button
My gutted and modified button code
-- Note: Following functions can have more arguments if you need them
left\_workA = function(event)
-- LEFT WORK A
end
left\_workB = function(event)
-- LEFT WORK B
end
left\_workC = function(event)
-- LEFT WORK C
end
left\_workD = function(event)
-- LEFT WORK D
end
new\_left\_touch = function( event )
if event.phase == "began" then
left\_workA( event )
elseif event.phase == "moved" then
left\_workB( event )
elseif event.phase == "ended" or event.phase == "cancelled" then
left\_workC( event )
end
left\_workD( event )
end
leftButton:addEventListener("touch",new\_left\_touch)
-- Assume similar for right button
My hypothetical swipe code
scrollMe = function (event)
if event.phase == "began" then
if( ??? is left swipe ??? ) then
left\_workA( event )
else
right\_workA( event )
end
elseif event.phase == "moved" then
if( ??? is left swipe ??? ) then
left\_workB( event )
else
right\_workB( event )
end
elseif event.phase == "ended" or event.phase == "cancelled" then
if( ??? is left swipe ??? ) then
left\_workC( event )
else
right\_workC( event )
end
end
left\_workD( event )
right\_workD( event )
end
swipeArea:addEventListener("touch",scrollMe)
I hope this helps. I know getting your head around touch inputs is challenging, especially when you introduce intermediate inputs like swiping. Just keep working at it. I know you’ll eventually crack this nut.
Cheers,
Ed
Roaming Gamer, LLC.
SSK for Corona SDK (github) (videos)
[import]uid: 110228 topic_id: 31894 reply_id: 127728[/import]