Better way of handling inputs?
Opened this issue · 0 comments
flamendless commented
Hey, i have questions. Consider the following:
local keys = {
a = "printA",
b = function() print("b") end,
}
local input = Input()
for k,v in pairs(keys) do
input:bind(k, v)
end
local function printA() print("a") end
If i press "a", it will call the printA function.
If i press "b" it will use the anonymous function passed.
Now, what if i want to check in update the key "a" if it is down?
function love.update(dt)
if input:down("a") then printA() end
--or
if input:down("printA") then printA() end
end
Isnt this repetitive?
I suggest, add an argument to bind that determines whether the binded key is for "down", "keypress", or "keyreleased" like
input:bind("a", "printA", "down") --default would be "keypressed"
This way, the library can check and call it internally without having to redo the if-statements
Clarify me if im wrong.