Creating a body without adding it to the physics world?

HexDump

04-02-2008 22:57:06

Hi all,

Is there anyway to precreate a body whitout having it added authomatically to the world?.

I need this in order to precreate a pool of entities with all its parts ready to go. But I have noticed that there's only a way to create a body, and it adds the body authomatically to the world Sad.

I would like to do something like this:

1) Create Entity (nothing is added to the physics world, but collision and body for the entity are been created).
2) Add the Entity to the game world. The entity body is added to the physics world.
3) Remove entity from the game world. The entity body is removed form the world but not deleted. It is ready to be added again if I re-add the entity to the world.

Note: I could freeze the bodies after creation, but I think this isn´t a good option (Think about a pool of 300 entities Smile ). By the way I have read that when creating a body it is authomatically added to the simulation list, so, to the world.

Thanks in advance,
HexDump.

walaber

07-02-2008 00:26:34

You can basically do this... here is how:

1. on initial creation, create the Collision object that describes the shape of the body.

2. when you need a Body, create a "new" Body object, using the Collision that you already have stored.

3. when you are done with the body, "delete" the Body, but not the Collision object.

4. when you need another body, repeat from step 2.


the overhead of calling new and delete on the Body object should be minimal. Is there something about your project that won't work with this approach?

HexDump

08-02-2008 08:12:58

No, this should work ok, just it wasn´t what I´m used to do. I use to precatch everything and "add to scene" when needed. But theres's no problem to have some new/deletes.


Thanks in advance,
HexDump.

Beauty

06-05-2008 12:59:03

I have a similar question:

After calling Freeze() for a Body it's excluded from physics calculation.
I suppose, then it's also excluded from the ContactCallback functions UserBegin / UserProcess / UserEnd.
Is this right? :?:

pra

06-05-2008 23:11:43

I have a similar question:

After calling Freeze() for a Body it's excluded from physics calculation.
I suppose, then it's also excluded from the ContactCallback functions UserBegin / UserProcess / UserEnd.
Is this right? :?:

I doubt that.
it is unfreezed as soon as it collides with something, after all