1

嘿,我有这个问题,如果我点击并按住屏幕,玩家会在 Y 上加速。

我更喜欢的是玩家点击屏幕(并保持浮动)并且他以稳定的速度上升(没有变得更快)。

这是浮动速度和触摸事件的功能:

function activateJets(ship,event)
    ship:applyForce(0, -1.0, ship.x, ship.y)
    print("run")
end

function touchScreen(event)
    print("touch")
    if event.phase == "began" then
        ship.enterFrame = activateJets
        Runtime:addEventListener("enterFrame", ship)
    end
    if event.phase == "ended" then
        Runtime:removeEventListener("enterFrame", ship)
   end    
end

Runtime:addEventListener("touch", touchScreen)

对不起,如果这没有意义。这是我想要的总体思路:

  • 玩家触摸屏幕(并保持)
  • 然后物体以一致的速度漂浮起来(没有速度增益)
  • 播放器释放触摸
  • 物体正常掉落
4

1 回答 1

0

所涉及的物理学会阻止您这样做:您正在对您的船施加恒定的力。根据牛顿定律(由物理库模拟),这意味着恒定的加速度,因此速度线性增加。

您想要的行为(与真实物理不一致)是立即加速到您的目标速度,然后没有速度变化。因此,使用函数shipSetLinearVelocity()内部将船的速度设置为恒定值就足够了activateJets。当然,当触摸结束时,您应该将速度重置为零。

于 2013-10-13T19:31:28.343 回答