如何使用Lua和Corona SDK让身体向上移动?

这是我想要增加向上速度的对象:

local myImage = display.newImage( "rose.png" )
myImage.x = 320
myImage.y = 500
myImage.rotation = 0
physics.addBody( myImage, { density=0.1, friction=2.0, bounce=0.0,velocity=-40 } )

给对象增加向上速度的函数:

local function test()
myImage:setLinearVelocity(0, -20)
end
test()

但是对象没有向上移动,这是我的物理引擎设置:

添加物理引擎
local physics =require("physics")
physics.setGravity(0,0.9)
physics.start()
点赞
用户1592982
用户1592982

你的对象的线性速度受重力影响。你可以通过运行时 enterFrame 监听器每帧设置线性速度,或者通过以下方式关闭 myImage 对象的重力:

myImage.gravityScale = 0

在添加物理体之后。

2013-07-28 20:08:50
用户1444321
用户1444321

尝试将重力的 y 值设为负数。

physics.setGravity(0, -0.98)
2014-02-04 06:13:33