You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The module is designed to be compatible with any Lua engine that can get delta-time between update cycles and accelerometer data.
Example of usage with Love2d (free 2d Game Engine):
main.lua
functionlove.load()
shakeDetector=require"shakeDetector"localjoysticks=love.joystick.getJoysticks()
joystick=joysticks[#joysticks]
endfunctionlove.update(dt)
localx, y, z=joystick:getAxes()
shakeDetector:update(dt, x, y, z)
endfunctionlove.draw()
love.graphics.print(shakeDetector.count)
end
API
Update shake detector
update(dt, x, y, z) arguments: delta-time between update cycles, accelerometer data x-axis, y-axis, z-axis
Get shakes count
localshakesCount=shakeDetector.count
Changing threshold and timeout:
shakeDetector:reset() -- reset to defaults (threshold = 0.5, timeout = 0.25)shakeDetector:reset(0.6, 0.3) -- set threshold to 0.6 and timeout to 0.3shakeDetector:reset(nil, 0.4) -- set threshold to default (0.5) and timeout to 0.4shakeDetector:reset(0.2, nil) -- set threshold to 0.2 and timeout to default (0.25)