Love2D: 当我按上或下键时停止玩家移动

这是我的玩家移动方式:

if love.keyboard.isDown("right") then
    player.x = player.x + player.speed * dt
end

if love.keyboard.isDown("left") then
    player.x = player.x - player.speed * dt
end

我想要实现的是,当按下上下方向键时,停止玩家移动。

点赞
用户2698261
用户2698261

你可以将这些 if 语句包装在另一个 if 语句中,使用 notand 关键字:

if not love.keyboard.isDown("up") and not love.keyboard.isDown("down") then
   -- 这里放左/右移动的检查代码
end
2014-08-18 09:14:55