Here’s a library that I made for easy handling of taps, swipes, and long presses. No code is required for it to start handling things, it runs on its own. Also, as the touch function works, you don’t have to have all your functions existing (if you only want feedback from tapped(tap), you don’t have to imeplement swiped(swipe) etc.)
If you need some documentation, I wrote nearly 100 lines of it at the top of Main. Go nuts.
A video of the demo for anyone who’s too lazy to paste it into Codea (I know I would be, but this would motivate me):
Help! @SkyTheCoder
I cannot find the error in this line from your Flickable github code
I’m on ios 8.2, CODEA 2.3
function getBoolFromAngle(angle)
local a = angle --+ Flickable.angleOffset
local tolerance = 45.0
if Flickable.useCorners then
tolerance = 67.5
end
return {up = a > 90 - tolerance and a < 90 + tolerance
, down = a < -90 + tolerance and a > -90 - tolerance <=line marked in red?
, right = a < tolerance and a > -tolerance
, left = a > 180 - tolerance or a < -180 + tolerance}
end
Is the tween.delay really guaranteed to execute your lambda after all code has been parsed? I.e. Is there no chance that Main defines touched after your lambda has run? Nice gimmick though
Ah @skythecoder, so you mean that tween only assesses whether the delay is over at each frame, which means by definition that the program has really started (and has been completely parsed). Makes sense.
@joelhoro Right before each draw is called each frame, the tween library goes over all registered tweens and checks if they are over. When if finds one, it calls its callback. Because it only calls it before draw is ran, all the code has been loaded and setup has been ran. I delay it overwriting the touched function by one frame so it can’t be overwritten by the one in Main while the code is loading, since dependencies are loaded first.
swiping. i do the swipe, then the animation happens afterwards. It doesn’t track with my finger. check out candycrush if you want to see what a perfect swiping system looks like
@matkatmusic It only counts the swipe when you lift up your finger. What if, for instance, you started a gesture which looked like a swipe, but then you turned the direction at the end? It wasn’t a swipe, and if it triggered the swipe gesture before the gesture finished, it would have been inaccurate.
i guess i was expecting a snap-to-grid type movement while it tracks with my finger, and the piece being snapped was allowed to only move 1 grid space. right now, the behavior is almost like:
touched screen? yes
moved finger in some direction? yes
finger lifted up? yes
ok, which direction did we move?
ok, figured out the direction, now do the gamepiece animation of it moving in the direction of the finger move.
BTW, is touch.tapCount a new thing? I searched through all the posts where people talked about detecting double taps, and I never saw anyone mention it.
Then I just noticed it in the autocomplete when I was writing touch. It seems to solve the problem completely.