Reputation: 75
so i was making a game, and ran into a bug where love.keyboard.isDown()
detected a key being pressed more than once
code:
function love.update(dt)
if love.keyboard.isDown("escape") and Menu == false then
Menu = true
elseif love.keyboard.isDown("escape") and Menu == true then
Menu = false
end
when pressing the esc
key, the game goes crazy switching between the menu and the gameplay. is there a way to avoid this?
Upvotes: 0
Views: 777
Reputation: 2813
Sometimes this behaviour is wanted and sometimes not.
If you dont want this behaviour simply use...
local debug = false
function love.keyreleased(key)
if key == 'd' then
if debug then debug = false else debug = true end
end
if key == 'r' then
love.event.quit('restart')
end
end
Behaviour:
Look: https://love2d.org/wiki/love.keyreleased
Upvotes: 1
Reputation: 1539
love.keyboard.isDown(key)
checks whether a key is held down, which is usually a few frames even for a short press.
Take a look at https://love2d.org/wiki/love.keyboard.isDown.
In your case you probably want the love.keypressed
event, which only triggers once (https://love2d.org/wiki/love.keypressed)
Upvotes: 2