Page 1 of 1
Any key using .isDown
Posted: Mon Feb 04, 2013 10:43 am
by Gurrlin
I'm wondering how to check all keys in an efficient way using keyboard.isDown and joystick.isDown. I know these functions take multiple parameters but having to include all keys/buttons, especially the keyboard seems really awkward to me.
Re: Any key using .isDown
Posted: Mon Feb 04, 2013 12:21 pm
by Robin
It might be a better idea to use
love.keypressed instead and just ignore the argument.
EDIT: or do this:
Code: Select all
local nkeysdown = 0
function love.keypressed(key, u)
nkeysdown = nkeysdown + 1
-- the rest of love.keypressed
end
function love.keyreleased(key, u)
nkeysdown = nkeysdown - 1
-- the rest of love.keyreleased
end
And then instead of having something like
if love.keyboard.isDown(any) then, you do
if nkeysdown > 0 then.
Re: Any key using .isDown
Posted: Mon Feb 04, 2013 1:18 pm
by Gurrlin
Ah, yes that makes sense, thanks!