1

我希望我的显示对象在屏幕上以一定速度移动并且没有任何交互。我怎么能用电晕做到这一点?谢谢。

4

1 回答 1

4

首先,您必须将显示对象添加到物理场,然后将其速度设置为随机值。您可以使用计时器定期更改显示对象的移动。例如:

physics = require("physics");
physics.start()
rectangle = display.newRect(0, 0, 50, 50)
physics.addBody(rectangle, "kinematic", {isSensor = true})
function moveRandomly()
rectangle:setLinearVelocity(math.random(-300,300), math.random(-300,300));
end
timer.performWithDelay(500, moveRandomly, -1);
于 2012-07-05T11:01:27.530 回答