跳跃时输入延迟
Input lag when I jump
我正在使用 lua 和 Löve2D 开发一个小游戏,我使用这段代码让我的角色跳跃:
epsilon = 0.1
x,y = player.body:getLinearVelocity()
if math.abs(math.ceil(y)) < epsilon then cantJump = false else cantJump = true end
if love.keyboard.isDown(" ") and not cantJump then player.body:setLinearVelocity(0,-500) end
player.body:setAngle(0)
player.body:setX(math.ceil(player.body:getX()))
player.body:setY(math.ceil(player.body:getY()))
end
但有时,当我按下 space 按钮时,我必须等待很短的时间才能看到播放器跳跃。我该如何解决?
我认为问题出在math.ceil。尝试移除它,因为它正在改变玩家的位置,或者在你告诉它跳跃之前将它移动到。
我正在使用 lua 和 Löve2D 开发一个小游戏,我使用这段代码让我的角色跳跃:
epsilon = 0.1
x,y = player.body:getLinearVelocity()
if math.abs(math.ceil(y)) < epsilon then cantJump = false else cantJump = true end
if love.keyboard.isDown(" ") and not cantJump then player.body:setLinearVelocity(0,-500) end
player.body:setAngle(0)
player.body:setX(math.ceil(player.body:getX()))
player.body:setY(math.ceil(player.body:getY()))
end
但有时,当我按下 space 按钮时,我必须等待很短的时间才能看到播放器跳跃。我该如何解决?
我认为问题出在math.ceil。尝试移除它,因为它正在改变玩家的位置,或者在你告诉它跳跃之前将它移动到。