Flickable - Easy touch library for taps, swipes, and long presses

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):


Edit: Just realized that YouTube automatically made the video zoom in and out halfway in…ignore that, YouTube is weird.

View via GitHub

View via Pastebin

View via Codepad

Not available via Codea Communtiy, sorry about that!

Install it by long pressing “add new project” with the code copied, and select “paste into project.”

To set it up in your project, add it as a dependency. It’s already working. No flickable = Flickable() or flickable:touched(touch) required.

very nice work @Skythecoder

I haven’t got a chance to try it out yet, but it looks really cool

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
    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}



@CodingOnNapkins Scroll down to the bottom and find a tween.delay(0, function()... line, and change the 0 to 0.001. It was a change in Codea 2.3.

@SkyTheCoder Thanks, that worked when I found both tween.delay(0’s

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

@joelhoro tween.delay(0.001, function()...end) is guaranteed to run the code the next frame, unless you can get over 1,000 FPS.

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.

very well, so easy handling

Is there a way to speed up the responsiveness?

@matkatmusic What do you mean by speed up? Which part isn’t responsive enough? Do you mean swiping, tapping, long pressing…?

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. 

Hi @SkyTheCoder, I was excited to try your library, but it doesn’t run for me. I get a red error pointer at line 96, with the cryptic message:

time must be a positive number. Was 0

Is there an easy fix I can just put in myself?

Tween time can’t be 0 anymore, it has to be some thing very small like 0.001. It’s the tween delays on lines 98 and 178.

@yojimbo2000, thanks.

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.

If you forum search tapcount there’re 120 results going back to 2011. So I guess not!