Module m.gesture
Gesture detection module that can be used to detect gestures such as tap, double tap,
long press and swipe
Usage:
local gesture = require "ludobits.m.gesture"
function on_input(self, action_id, action)
local g = gesture.on_input(self, action_id, action)
if g.tap then
print("Single tap detected")
elseif g.double_tap then
print("Double tap detected")
elseif g.long_press then
print("Long-press detected")
elseif g.swipe_left then
print("Swipe left detected")
elseif g.swipe_right then
print("Swipe right detected")
elseif g.swipe_up then
print("Swipe up detected")
elseif g.swipe_down then
print("Swipe down detected")
end
end
TAP_THRESHOLD |
maximum distance between a pressed and release action to consider it a tap |
DOUBLE_TAP_INTERVAL |
maximum interval allowed between two taps to consider it a double-tap |
SWIPE_THRESHOLD |
minimum distance between a pressed and release action to consider it a swipe |
SWIPE_TIME |
maximum time between a pressed and release action to consider it a swipe |
LONG_PRESS_TIME |
minimum time of a pressed/release sequence to consider it a long press |
-
on_input (self, action_id, action)
-
Forward calls to on_input to this function to detect supported gestures
Parameters:
Returns:
A table containing detected gestures. Can contain the following
values:
* tap [boolean]
* double_tap [boolean]
* long_press [boolean]
* swipe_left [boolean]
* swipe_right [boolean]
* swipe_up [boolean]
* swipe_down [boolean]
* swipe - table with values from, to and time
-
TAP_THRESHOLD
-
maximum distance between a pressed and release action to consider it a tap
-
DOUBLE_TAP_INTERVAL
-
maximum interval allowed between two taps to consider it a double-tap
-
SWIPE_THRESHOLD
-
minimum distance between a pressed and release action to consider it a swipe
-
SWIPE_TIME
-
maximum time between a pressed and release action to consider it a swipe
-
LONG_PRESS_TIME
-
minimum time of a pressed/release sequence to consider it a long press