2

我正在使用 NDK 中的 Box2d 物理引擎在 android 中编写游戏。所以物理完全在原生世界中,但绘图仍然在 Java 世界中。

在我的游戏中,我有一个更新线程,它会步进物理世界并使画布无效以进行重绘。到目前为止,一切都很好。当用户希望暂停游戏时,我会停止所有线程。然后用户可以选择“恢复”游戏,这将重新启动线程,游戏将从停止的地方开始。

出于某种原因,当游戏重新开始时,物理中的物体移动得更快。如果停止并重新启动身体的时间步长,为什么会有任何变化?

暂停后再次调用 step() 是否有问题?短暂的停顿后,身体的速度、质量、摩擦、密度会发生变化吗?

感谢任何帮助谢谢

4

1 回答 1

1

This question is old, but just in case you haven't resolved it, a few thoughts come to mind:

  • Are you passing a constant value to step()? If you're calculating that value at all based on the amount of real time that's passed, that can be your problem.
  • Are you sure you're only creating a single thread? When you resume, if you resume the old thread and accidentally create another, you could get 2x the updates.
  • How do you lock the frame rate to real time -- is it possible you're not updating that calculation to the new time? As in, if you have a "last update" that you check to make sure at least 1/60th of a second has passed, if you don't reset the "last update" value on resume, then EVERY update will succeed, regardless of whether that amount of time has passed.
于 2011-06-23T19:20:26.610 回答