Hi there!, I’m not happy with this particular chunk of my code, as is not really working fine in the device. the logic for the game is related with swipes, touches, gestures, that in some cases must be done quick.
It’s a function to check the swipe direction, the issue is that if I set minSwipeDistance to something lower than 25, swipes are mistaken with touches and if I set a higher value my game is not as dynamic as I wish…
I wonder if somebody could advice or suggest a better approach for this function:
function playAreaSingle:checkSwipeDirection( event, isDoingTouch )
assert(isDoingTouch, "bDoingTouch erroneo en playArea:checkSwipeDirection")
local xDistance
local yDistance
local minSwipeDistance = 25
local totalSwipeDistanceLeft
local totalSwipeDistanceRight
local totalSwipeDistanceUp
local totalSwipeDistanceDown
local xStart, yStart = event.xStart, event.yStart
local xEnd, yEnd = event.x, event.y
if isDoingTouch == true then
xDistance = math.abs(xEnd - xStart)
yDistance = math.abs(yEnd - yStart)
if xDistance \> yDistance then
if (xStart \> xEnd )then
totalSwipeDistanceLeft = xStart- xEnd
if (totalSwipeDistanceLeft \> minSwipeDistance) then
-- Es swipe LEFT
return "left"
else
-- Es touch
return "Touch"
end
else
totalSwipeDistanceRight = xEnd - xStart
if (totalSwipeDistanceRight \> minSwipeDistance) then
--Es swipe RIGHT
return "right"
else
--Es touch
return "touch"
end
end
else
if (yStart \> yEnd )then
totalSwipeDistanceUp = yStart - yEnd
if (totalSwipeDistanceUp \> minSwipeDistance) then
--Es swipe UP
return "up"
else
--Es touch
return "touch"
end
else
totalSwipeDistanceDown = yEnd - yStart
if (totalSwipeDistanceDown \> minSwipeDistance) then
--Es swipe DOWN
return "down"
else
--Es touch
return "touch"
end
end
end
return false
end
end
Thanks in advance!. [import]uid: 8933 topic_id: 26149 reply_id: 326149[/import]