物体在下落时不断加速

Object keeps accelerating as it falls

我对此一窍不通,但无论如何。我正在编写一个应用程序,在该应用程序中,您必须点击才能让物体上升,但在某些时候,无论您点击多快,物体都会继续下降。好像引力越来越大

编辑:我不知道给出什么代码示例,因为我不知道其中是否有意义,但我会尝试:

这就是我创建对象的方式:

super=display.newImage("mine.png")
super:setReferencePoint(display.BottomLeftReferencePoint)
super.y=display.contentHeight+70
super.x=display.contentWidth/2.3
super.gravityscale=1
superIntro = transition.to(super,{time=2000, y=display.contentHeight/1.2, onComplete= supergo})
physics.addBody(super, "dynamic", {density=0, bounce=0, friction=0, radius=12})`

这是我认为相关的脚本的一部分:`

function scrollCity(self,event)
    print("touch")
    if self.y > 930 then
        self.y = 0
    else
        self.y=self.y+scrollspeed*6
    end
end

function activateJets(self,event)

self.y=self.y-scrollspeed*6
print("run")
end

function touchScreen(event)
print("p")
if event.phase == "began" then

    if super.y<display.contentHeight/1.2+6 then
        super.y=display.contentHeight/1.2
        background1.enterFrame = scrollCity
        Runtime:addEventListener("enterFrame", background1)
        background2.enterFrame = scrollCity
        Runtime:addEventListener("enterFrame", background2)
    else

        super.enterFrame = activateJets
        Runtime:addEventListener("enterFrame", super)
    end

 end
if event.phase == "ended" then

    Runtime:removeEventListener("enterFrame", super)
    Runtime:removeEventListener("enterFrame", background1)
    Runtime:removeEventListener("enterFrame", background2)

end
end

EDIT2:设置重力:

physics.setGravity( 0, 1.5 )

一开始轻点几下就可以让它一直在屏幕上,但几秒钟后就无法维持了,它就掉下来了。我希望它以相同的速度下降而不是加速。

它一直在加速的原因是重力施加了一个恒定的力。任何受重力影响的东西都会加速,而不是固定速度。

对于恒速运动

通过将 gravityscale 设置为 0 或将全局重力设置为 0 来取消重力的影响 - 以更适合您的方式为准 - 然后使用 super:setLinearVelocity( xVelocity, yVelocity ) 设置 super 的速度。

对于有加速度的运动

如果您更喜欢加速重力,那么您现在使用的方法很好,但您可能会考虑 super:setLinearVelocity(0, 0) 当轻敲发生时,物体会从静止状态下落,而不是继续快速下落。