How to Remove Collided Bodies after 2 seconds

At present ,I am able to remove the collided bodies immediately.

My requirement is to remove them after a certain time delay... How to do this?

I don't have any idea of how to do this...

I tried to remove the body after sometime using NSTimer but that did not work out,because the world object will have continuous simulation (up-dation)
I also tried Using NSThread to sleep for certain time interval but that also went in vain....

Any help appreciated....Thanks in advance
Create the manager message
what is Create the manager message..

I don't know anything about it can u please tell me something about this
Finally,I got it.... Is this the right way to do?

if (b->GetLinearVelocity().Length()< 0) {
[self schedule:@selector(removeBody:) interval:0.1];
}

Collided bodies to come to rest, takes some time.. that time span is enough for my requirement
This isn't really a Box2d question, but anyway...
I wouldn't use any timers or threads to remove things from the Box2d world because they could fire in the middle of stepping the world, which could cause a crash.
Why not just mark the body as 'scheduled for removal' (put it in a list or something), and note the time that you decided so. Then each timestep, or every x timesteps, look in the list for bodies that were marked for removal more than 2 seconds ago, and remove them before doing the world step.
that was a great reply... irresistible force
I had the same problem and this is what I did it works pretty well...

Code: Select all

   
id action = [CCSequence actions:
             [CCDelayTime actionWithDuration:1.0],
             [CCCallFunc actionWithTarget:self selector:@selector(toDestroy)],
             nil];
   [self runAction:action];


the @selector(toDestroy) is simply get list and DestroyBody
I am face this problem.my problem is solve

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