2
votes

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

1
Hi, could you share a few details on how you got the application to work with NDKSameer Segal
Hi Sameer, it is a multi step process that I did not document. I can write up something and share it with you sure. I will post it in a blog or something and share the link here.wysiwyg

1 Answers

1
votes

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.