0
votes

This is re-question

I want to destroy bodies after collision but with an delay of 4-6 seconds. I am successful in detection of collision & destruction of body after collision but now i want a delay in it.

I don't know how to delay.

1

1 Answers

0
votes

Make One function which will take B2Body as argument and call that function with delay.

Call function like this:

std::vector<b2Body *>::iterator pos; 
for(pos = bodyToDestroy.begin();pos != bodyToDestroy.end(); ++pos){ 
b2Body *body = *pos; 
if(body->GetUserData() != NULL){ 
CCPhysicsSprite *sprite = (CCPhysicsSprite *) body->GetUserData(); 
[sprite removeFromParentAndCleanup:YES];
} 
[self performSelector:@selector(myfunc) withObject:body afterDelay:4.0]; 
}

And The function will be

-(void)myfunc : (b2Body *)body{
    world->destroyBody(body);
}