Shake Detection Library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
azoyan
Prole
Posts: 25
Joined: Wed Dec 27, 2017 5:19 pm

Shake Detection Library

Post by azoyan »

It is porting of shake.js library to Lua.
https://github.com/azoyan/ShakeDetectorLua

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:

main.lua

Code: Select all

function love.load()
    shakeDetector = require "shakeDetector"
    local joysticks = love.joystick.getJoysticks()
    joystick = joysticks[#joysticks]    
end

function love.update(dt)    
    local x, y, z = joystick:getAxes()
    shakeDetector:update(dt, x, y, z)
end

function love.draw()
    love.graphics.print(shakeDetector.count)
end
Get shakes count

Code: Select all

local shakesCount = shakeDetector.count
Changing threshold and timeout:

Code: Select all

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)
azoyan
Prole
Posts: 25
Joined: Wed Dec 27, 2017 5:19 pm

Re: Shake Detection Library

Post by azoyan »

This can be useful to someone.
Who can resolve pull request https://github.com/love2d-community/awe ... d/pull/130 or add to avesome-love2d (or awesome -lua maybe?)
Post Reply

Who is online

Users browsing this forum: alexjgriffith and 2 guests