tap and hold , so how long until you consider “hold = true?”
and swipe is about changing x,y value within a certain time and distance
if touch.state == BEGAN then
myTimer = 0
startX = touch.x
elseif touch.state ~= ENDED then
myTimer = myTimer + DeltaTime
if myTimer > myLimit then
held = true
end
if held and math.abs(startX - touch.x > 20) then
swipe = true
end
else
held = false
end
this gets a bit more complex with multiple fingers
@Dezmo here is a basic touch tracker code I’ve had kicking around for a few years. I think it predates the new gesture functions in Codea, but adopts the same approach as @skar talks about.
@West THAT TOUCH TRACKER IS HARD ASH
I’m gonna be dissecting it for some time now to learn from it. Really loving the lock on animation after holding on for a moment
@West - great little demo and cool routines. Will take a little digesting but looks like a lot of useful code there.
By the way, stopped the demo and logged into Safari on the forum to post this note and Codea crashed. Not sure why.
@dave1707@Simeon - please note, posted the crash report. Had a couple like this recently, do you think it could be changes in iOS or the direction Codea is now moving in?
Here’s an example that shows a short press, a long press, a swipe distance, and a swipe angle. The swipe angle is 0 to the right, 90 at the top, going counter clockwise.
viewer.mode=FULLSCREEN
function setup()
s=require("socket")
pressDuration=.25 -- time cutoff between a short and long press
swipeLimit=20 -- distance limit for a swipe
shortPress,longPress,swipeAngle,swipeDist=0,0,0,0
fill(255)
end
function draw()
background()
text("Short Press "..shortPress,WIDTH/2,HEIGHT/2)
text("Long Press "..longPress,WIDTH/2,HEIGHT/2-50)
text("Swipe Distance "..swipeDist,WIDTH/2,HEIGHT/2-100)
text("Swipe Angle "..swipeAngle,WIDTH/2,HEIGHT/2-150)
end
function touched(t)
touchControl(t)
end
function touchControl(t)
if t.state==BEGAN then
shortPress,longPress,swipeAngle,swipeDist=0,0,0,0
st=s:gettime()
tx,ty=t.x,t.y
end
if t.state==ENDED then
local diff=s:gettime()-st
if diff<pressDuration then
shortPress=diff
else
longPress=diff
end
swipeDist=vec2(t.x,t.y):dist(vec2(tx,ty))
if swipeDist>swipeLimit then
swipeAngle=(math.deg(math.atan2(t.y-ty,t.x-tx))+360)%360
end
end
end