开发者

Box2d body moves faster after step is stopped and restarted in a pause [Android]

I am writing a game in android using Box2d physics engine in NDK. So physics is entirely in the native world but the drawing is still in Java world.

In my game I have an update thread that steps the physics world and invalidates the canvas for redraw. So far so good. When the user wishes to pause the 开发者_运维问答game I stop all the threads. Then user is given an option to "Resume" the game which would restart the threads and the game would begin from where it stopped.

For some reason, when the game is resumed the bodies in the physics move faster. Why would anything change for a body if its time stepping is stoppped and restarted ?

Is there an issue with calling step() again after making a pause ? does the body's velocity, masss, friction , density change after a brief pause.

Any help is appreciated Thanks


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜