Optimizing physics calculations

irresistible force wrote:
Does the speed improve if you get rid of those offscreen objects completely?
If they are inactive and invisible, do you still need them?

Yes, It was horrible until I did that optimization.
and yes, I need them cos when collision occurs I have to do backward action to move objects back to their position.

so I think there is no better way than deactivating physics body if object is not needed for calculations...
So you're saying you only have 10 objects on the screen being drawn and using physics, and yet the performance is jerky?
What I'm asking is, does the performance improve if off-screen objects are destroyed completely (not just inactive and non-rendered).
If you try destroying objects that go off-screen, then we will know if it's the off-screen objects that cause the slowdown, or the on-screen ones.

Is it possible to re-create the bodies when a backward action occurs, instead of keeping hundreds of bodies off-screen and re-activating them?
About my question from earlier, do the shapes really need 20 points? It seems like a lot. How is the performance if you use a single circle fixture instead of the complex polygon?

Another good question would be, if you just use SetLinearVelocity to start the bodies moving and then let them go as the physics engine would do (don't set the positions from sprites), does the jerky movement still happen?

Original thread: https://box2d.org/forum/viewtopic.php?t=9783