Touch screen swipe

Hi,
I’m assuming I’d have to write a touch screen swipe input?
Such as up, down, left & right?
Thanks,

David

Yes, there’s no built in support for gestures. If you keep track of action.pressed, action.released, direction, distance and time then that should be enough to determine if the gesture was a swipe and if so in what direction. I’m sure there are some guidelines on the threshold values to distinguish between a fling, swipe and a drag.

OK, thanks. I’ll give it a go.

How do you go about accessing time?
I figured out how to get difference of action.pressed(action.y) and action.released(action.y) and used that as telling me if character moves up or down, but how do I know how long the touch was held?

1 Like

You can use os.time() for time stamp in full seconds or socket.gettime() for millisecond precision.

1 Like

Thank you. I’d found os.time(), it wasn’t a good fit as swipes are less than a second.
Will use socket.gettime() and see how that works.
New to LUA also.

1 Like

simple swipe script

7 Likes

I managed to do mine based on this Java script: http://www.javascriptkit.com/javatutors/touchevents2.shtml
Obviously, it’s up to you, but I think you need to add a timer. If it takes 10 seconds to swipe 50 pixels, I don’t think that counts as a swipe.

6 Likes

Yes, you right. Thanks. :thumbsup:
I made changes to gist.

3 Likes

If you don’t need a multi touch, this version of swipe script more stable on old devices than previous (using mouse trigger):

2 Likes