Corona SDK 移动物体不受重力影响

Corona SDK move object without it being effected by gravity

所以我正在尝试制作一个 Flappy Birdesque 游戏来学习如何使用 Corona SDK 制作游戏。我有一个顶部列,我希望它能够线性移动。所以我使用的是 topColumn.setLinearVelocity(),但我还在游戏中设置了重力,这样小鸟就可以正常拍打翅膀了 :)。但我的问题是,当游戏开始时,管道会因重力而掉到地上。有没有办法在不受重力影响的情况下移动 topColumn 和 bottomColumn?它们现在是动态物体,但我不知道如何使用静态移动它们。

有什么帮助吗?

local physics = require "physics"
physics.start()
physics.setGravity( 0, 100 )
...
function addColumns()
 
 height = math.random(display.contentCenterY - 200, display.contentCenterY + 200)

 topColumn = display.newImageRect('topColumn.png',100,714)
 topColumn.anchorX = 0.5
 topColumn.anchorY = 1
 topColumn.x = display.contentWidth
 physics.addBody(topColumn, "dynamic", {density=0, bounce=0, friction=0})
 topColumn.y = height - 160
 topColumn:setLinearVelocity( -20,0 )
 
 bottomColumn = display.newImageRect('bottomColumn.png',100,714)
 bottomColumn.anchorX = 0.5
 bottomColumn.anchorY = 0
 bottomColumn.x = display.contentWidth
 bottomColumn.y = height + 160
 physics.addBody(bottomColumn, "dynamic", {density=0, bounce=0, friction=0})
 bottomColumn:setLinearVelocity( -20,0 )

end 
...

听起来你需要运动机构。

来自科罗纳 documentation

"dynamic" — dynamic bodies are fully simulated. They can be moved manually in code, but normally they move according to forces like gravity or reactionary collision forces. This is the default body type for physical objects in Box2D. Dynamic bodies can collide with all body types.

"static" — static bodies does not move under simulation and they behave as if they have infinite mass. Static bodies can be moved manually by the user, but they do not accept the application of velocity. Static bodies collide only with dynamic bodies, not with other static bodies or kinematic bodies.

"kinematic" — kinematic bodies move under simulation only according to their velocity. Kinematic bodies will not respond to forces like gravity. They can be moved manually by the user, but normally they are moved by setting their velocities. Kinematic bodies collide only with dynamic bodies, not with other kinematic bodies or static bodies.