【问题标题】:Input lag when I jump跳跃时输入延迟
【发布时间】:2015-08-15 14:34:05
【问题描述】:

我正在开发一个使用 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

但有时,当我按下空格键时,我必须等待很短的时间才能看到玩家跳跃。我该如何解决?

【问题讨论】:

  • 你为什么在这里使用math.ceil()
  • 旁注:最好对变量使用正语义:canJump 而不是 cantJump

标签: lua box2d love2d


【解决方案1】:

我认为问题出在 math.ceil 上。尝试移除它,因为它正在改变玩家的位置,或者在你告诉它跳跃之前将它移动到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多