Destroy and re-create world?

Hi,

I think this will be a simple one 😀 (I hope)

Say I have 10 created physics objects on my screen. I press a button, and I want them all to be destroyed (or hidden) so that they can not be used again until I press another button to re-create them, at which time all of the objects are brought back to life and are in their same location they were prior to the destroying or hiding of the world.

Thx for all help! 🙂
One approach to 'hiding' the objects would simply be to move them off screen,
in the userdata, add an oldXPosition, and oldYposition, then you could physically
move the objects wherever you please, and put them to sleep/freeze them

i.e.
Code:
    public function freeze(tempBody:b2Body){
            if (!tempBody.IsFrozen() )
            tempBody.m_flags ^= b2Body.e_frozenFlag;
    }

Is a dirty approach, but gets the job done.

Another approach, if you're using simple shapes, would be to fill a Vector
with the shapes you used on createShape, and set the shapes to sensors,
i.e. immoveable, uncollideable, and hide the objects visual userdata, like
the movieclip or sprite you used.

i.e. myShapes.push( myBody.createShape(circleDef) );
or lastShape = myBody.createShape(circleDef);

then you can use something like
(myShapes[ct] as b2Shape).m_isSensor = true;
(myBody[ct] as b2Body).setMassFromShapes(); //not entirely sure you need to recalculate this

and to stop flash drawing the object
(myBody.userData.getUserData() as MovieClip).visible = false;
(off the top of my head)


Anyhoo, goodluck with this one, there's a good few options at your disposal.
Thanks, I will look into this.

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