Pooled objects, instantaneous positioning , Box2D problems

 sometimes need to move pooled sprites instantaneously into their correct display position.  

We have created an object pooling system, which allows us to reuse sprites as and when they come into view.

This works perfectly without physics bodies being added to the sprites. But once the sprites have a physics body assigned  the system acts up and sprites no longer appear where they should.

The only solution i have found is to remove the body from the physics simulation and add them back after the sprite position has been set.

The problem with this is that we have to keep recreating physics bodies when an object is reused from the pool and this defeats the objectives we are trying to achieve by object pooling. We want to pool both sprites and their associated physics bodies.

Any suggestions?

Hi @filippo22000,

I’ve created an “object pooling” method in app before, using physics, and it works as expected. Can you specify how you’re setting it up, and what exactly happens when you try to place a pooled object with a physics body versus one without a body?

Thanks,

Brent

Hi @filippo22000,

I’ve created an “object pooling” method in app before, using physics, and it works as expected. Can you specify how you’re setting it up, and what exactly happens when you try to place a pooled object with a physics body versus one without a body?

Thanks,

Brent