简体   繁体   English

如何移动“障碍物”。 Corona SDK物理Box2D。 物理更新?

[英]How to move “obstacle” objects. Corona SDK Physics Box2D. Physics Update?

I'm trying to understand the proper way to move "obstacle" objects in corona/box2d. 我正在尝试了解在corona / box2d中移动“障碍”对象的正确方法。 I want to know how to write my code so that the movement is deterministic and in-step with the physics engine. 我想知道如何编写代码,以便运动是确定性的,并且与物理引擎同步。 Is this possible? 这可能吗?

I'm familiar with Unity which has a physics update (FixedUpdate). 我熟悉具有物理更新(FixedUpdate)的Unity。 Where you can add a bit of code to execute on every physics step. 您可以在其中添加一些代码以在每个物理步骤上执行。 This keeps the physics deterministic, frame and system time independent. 这使物理确定性,框架和系统时间保持独立。

For example, in my game I want to do things like: Make a platform that moves back and forth, make an object that scales up and down in size. 例如,在我的游戏中,我想做以下事情:创建一个可以前后移动的平台,制作一个可以按比例缩放的对象。 I would still like the physics to work properly and allow the ball in my game to bounce off of these for example. 我仍然希望物理工作正常,例如,允许游戏中的球弹起。 Depending on the case, I imagine that I should use either kinematic or dynamic bodies . 我视情况而定,我应该使用运动学的或动态的物体

I've searched around and the way to periodically manipulate these objects is to use: 我搜索了一下,定期操作这些对象的方法是使用:

  • timer.performWithDelay . timer.performWithDelay But this has an issue mentioned in the docs "Timers run on system time. If the app is suspended, running timers will not be automatically paused" 但这在文档“计时器在系统时间上运行。如果应用已暂停,则运行中的计时器不会自动暂停”中提到了一个问题。
  • Listening to an enterFrame event. 监听enterFrame事件。 But this has a similar issue, if the frame rate drops then the object won't be moved enough. 但这有一个类似的问题,如果帧频下降,则对象将无法移动。 We can use delta time to deal with this, but this has determinism issues (moving an object too much on a lag spike). 我们可以使用增量时间来解决此问题,但这存在确定性问题(在滞后尖峰上移动过多的对象)。
  • transition.to . 过渡到 I'm guessing this is implemented with timer.performWithDelay and has the same issues. 我猜这是用timer.performWithDelay实现的,并且有相同的问题。

I don't think that any of these will behave deterministic. 我认为这些都不是确定性的。 Any suggestions? 有什么建议么? Thanks for the help. 谢谢您的帮助。

You should really use: 您应该真正使用:

object:setLinearVelocity(xVelocity, yVelocity)

or 要么

object:applyForce(xForce, yForce)

instead of transition.to. 而不是过渡到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM