Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/azoyan/ShakeDetectorLua
Shake Detector in Lua
https://github.com/azoyan/ShakeDetectorLua
accelerometer gamedev lua mit
Last synced: 2 months ago
JSON representation
Shake Detector in Lua
- Host: GitHub
- URL: https://github.com/azoyan/ShakeDetectorLua
- Owner: azoyan
- License: mit
- Created: 2019-02-22T10:36:38.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-16T11:28:34.000Z (over 5 years ago)
- Last Synced: 2024-08-02T06:22:29.736Z (6 months ago)
- Topics: accelerometer, gamedev, lua, mit
- Language: Lua
- Size: 30.3 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-love2d - ShakeDetectorLua - Uses accelerometer data for shake device detection written in Lua. (Utilities)
README
# Shake Detector Lua
It is porting of [shake.js](https://github.com/alexgibson/shake.js/blob/master/shake.js) library to Lua.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](https://love2d.org) (free 2d Game Engine):
**main.lua**
```Lua
function love.load()
shakeDetector = require "shakeDetector"
local joysticks = love.joystick.getJoysticks()
joystick = joysticks[#joysticks]
endfunction love.update(dt)
local x, y, z = joystick:getAxes()
shakeDetector:update(dt, x, y, z)
endfunction love.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
```Lua
local shakesCount = shakeDetector.count
```Changing threshold and timeout:
```Lua
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.3
shakeDetector:reset(nil, 0.4) -- set threshold to default (0.5) and timeout to 0.4
shakeDetector:reset(0.2, nil) -- set threshold to 0.2 and timeout to default (0.25)
```