检测到 love2d 键被多次按下
love2d key detected as being pressed more than once
所以我在制作游戏,运行 遇到了一个错误,其中 love.keyboard.isDown()
检测到一个键被按下了不止一次
代码:
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
当按下esc
键时,游戏会在菜单和游戏之间疯狂切换。有没有办法避免这种情况?
love.keyboard.isDown(key)
检查是否有按键被按下,即使是短按也通常是几帧。
看看https://love2d.org/wiki/love.keyboard.isDown。
在您的情况下,您可能需要 love.keypressed
事件,它只触发一次 (https://love2d.org/wiki/love.keypressed)
有时需要这种行为,有时不需要。
如果您不想要这种行为,只需使用...
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
行为:
- 按下按键 D 或 R => 没有任何反应
- 松开按键D或R => 触发功能
所以我在制作游戏,运行 遇到了一个错误,其中 love.keyboard.isDown()
检测到一个键被按下了不止一次
代码:
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
当按下esc
键时,游戏会在菜单和游戏之间疯狂切换。有没有办法避免这种情况?
love.keyboard.isDown(key)
检查是否有按键被按下,即使是短按也通常是几帧。
看看https://love2d.org/wiki/love.keyboard.isDown。
在您的情况下,您可能需要 love.keypressed
事件,它只触发一次 (https://love2d.org/wiki/love.keypressed)
有时需要这种行为,有时不需要。
如果您不想要这种行为,只需使用...
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
行为:
- 按下按键 D 或 R => 没有任何反应
- 松开按键D或R => 触发功能