【发布时间】: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。