Love2D键被发现不止一次
因此,我正在制作游戏,然后遇到一个错误,其中 love.kekeboard.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> ESC
键时,游戏在菜单和游戏玩法之间疯狂切换。有没有办法避免这种情况?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
love.keyboard.isdown(key)
检查是否固定键,即使在短按短片中,这通常是几帧。看看 https://love2d.org/wiki/wiki/love.key.keyboard.isboard.isdown 。
在您的情况下,您可能想要
love.keypressed
事件,它只触发一次( https://love2d.org/wiki/love.keypressed )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)有时这种行为是想要的,有时不是。
如果您不希望此行为简单地使用...
行为:
外观: https://love2d.org/wiki/wiki/love.keyreled.keyreled
Sometimes this behaviour is wanted and sometimes not.
If you dont want this behaviour simply use...
Behaviour:
Look: https://love2d.org/wiki/love.keyreleased