@ar2rsawseen I understand that you don't have enough time for it, I believe that would largely benefit new users to have access to that swipe class (for a start, with a lot of others ).
I didn't understand how to implement @adispose 's code.
Where is self.onFlingY defined? It is given as a parameter to the class constructor but where is it defined? (I am not asking you to answer)
Also in the following :
function SwypeDetector:doScroll(event)if onScroll ~=nilthen(...)
Shouldn't it be
if self.onScroll
? To my understanding, onScroll is not in the scope of function SwypeDetector:doScroll(event).
Also
function SwypeDetector:doScroll(event)if*onScroll* ~=nilthen
self.*onFlingY*(self.parent, self.lastX - event.touch.x, self.startY - event.touch.y)endend
shouldn't be :
function SwypeDetector:doScroll(event)if*self.onScroll* ~=nilthen
self.*onScroll*(self.parent, self.lastX - event.touch.x, self.startY - event.touch.y)endend
?
I didn't ask you about this because I know you don't have time to support someone else's code, and I thought it would take me even more time to understand if there are mistakes or I am misunderstanding. Nobody's been reporting mistakes, so maybe it's me.
Here is a version that I have built on top of different sources shared on the forum, and I have added several tricks that make it easy for me to customize my apps.
I have tried to comment the code, for what it's worth.
How to use :
--[[
-- ------------------------------------------------
-- CREATE AN INSTANCE OF THE GESTURES CLASS
-- ------------------------------------------------
options (optional):
- minDistance (int : default -> 100). The minimum distance to take swipes into consideration.
- maxDuration (float : default -> 0.5). The maximum duration to take swipes into consideration.
]]--local options ={minDistance =100, maxDuration =0.5}local gestures = Gestures.new(stage, options)--[[
-- ------------------------------------------------
-- ADD SWIPE CALLBACKS
-- ------------------------------------------------
Accepted : onSwipeUp, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUpLeft, onSwipeUpRight, onSwipeDownLeft, onSwipeRight
Note : Uncomment below to overwrite the default callbacks
-----------------------------
]]--
gestures:addCallback("onSwipeUp", function(swipe, event, options)print("Custom", "["..swipe.."]")end)--gestures:addCallback("onSwipeDown", function(swipe, event, options) print ("Custom", "["..swipe.."]") end)--gestures:addCallback("onSwipeLeft", function(swipe, event, options) print ("Custom", "["..swipe.."]") end)--gestures:addCallback("onSwipeRight", function(swipe, event, options) print ("Custom", "["..swipe.."]") end)--[[
-- ------------------------------------------------
-- ADD TOUCHES CALLBACKS
-- ------------------------------------------------
Accepted : touchesBegin, touchesMove, touchesEnd
Note : Uncomment below to overwrite the default callbacks
-----------------------------
]]----gestures:addCallback("touchesBegin", function(type, event, options) print ("On Touches Move >", event:getType(), "["..event.touch.x..":"..event.touch.y.."]") end)--gestures:addCallback("touchesMove", function(type, event, options) print ("On Touches Move >", event:getType(), "["..event.touch.x..":"..event.touch.y.."]") end)
gestures:addCallback("touchesEnd", function(type, event, options)print("", "On Touches End >", event:getType(), "["..event.touch.x..":"..event.touch.y.."]")end)--[[
-- ------------------------------------------------
-- MORE
-- ------------------------------------------------
-- Set gestures to inactive
gestures:setActive(false)
-- Check if gestures are active
gestures:isActive()
-- Remove all Callbacks
gestures:removeCallbacks()
-- Get all Callbacks
gestures:getCallbacks()
-- Remove callbacks
gestures:removeCallback("touchesBegin")
-- Free gestures
gestures:free()
]]--
Comments
I didn't understand how to implement @adispose 's code.
It is given as a parameter to the class constructor but where is it defined?
(I am not asking you to answer)
Also in the following :
if self.onScroll
To my understanding, onScroll is not in the scope of function SwypeDetector:doScroll(event).
Also
I didn't ask you about this because I know you don't have time to support someone else's code, and I thought it would take me even more time to understand if there are mistakes or I am misunderstanding.
Nobody's been reporting mistakes, so maybe it's me.
I will try @Tom2012 's one.
I have tried to comment the code, for what it's worth.
How to use :
which I will need to try my hand on