EZControls - Control handling made easy.
Posted: Tue Dec 08, 2015 10:46 pm
EZControls allows you to bind keys to binding objects and add onPress and onRelease callbacks to said objects. It sports support for separate bindings for different gamestates as well as built in utilities to help load and save keybinds to files in a human readable format.
GitHub
By default, it checks if the love key events are defined (love.keypressed(), etc) and defines them if they aren't. Functions for firing control events are provided in case they're defined.
Small Example:
Full example on GitHub.
GitHub
By default, it checks if the love key events are defined (love.keypressed(), etc) and defines them if they aren't. Functions for firing control events are provided in case they're defined.
Small Example:
Code: Select all
local controls = require('EZControls') -- Load the library.
controls.currentState = 'game' -- Set gamestate to "game". This will only allow bindings in the gamestate "game" to work. There's a special gamestate called "all" that can contain bindings that work regardless of current gamestate.
-- Bind some keys.
controls.state('game').binding('shoot'):bind(' ') -- Bind space to binding "shoot".
controls.state('game').binding('jetpack_fire'):bind({'up', 'w'}) -- Bind up and w to binding "jetpack_fire"
-- Traditional isDown check.
function love.update(deltaTime)
if controls.state('game').binding('shoot'):isDown() then
-- shoot gun logic
end
end
-- Callback style.
controls.state('game').binding('jetpack_fire'):onPress(function() -- Pass anonymous function as an argument to onPress function.
enableJetpack()
end)
controls.state('game').binding('jetpack_fire'):onRelease(function()
disableJetpack()
end)
local humanReadableKeybinds = controls.serialize() -- Dump keybinds to table.
controls.parse(humanReadableKeybinds) -- Load keybinds from table.