Page 1 of 1

How to remove shape and body after a delay in collision call

Posted: Wed Nov 10, 2010 1:30 am
by muniraj_143
can anyone help me to remove shape and body after a delay in collision callback.

By using cpSpaceAddPostStepCallback(sapce, (cpPostStepFunc)postStepRemove, blockShape, NULL);
i could safely remove the shape .
But i need some delay before i call the function.
Can anyone please help me with some sample code.
Thanks

Re: How to remove shape and body after a delay in collision call

Posted: Wed Nov 10, 2010 2:21 am
by slembcke
You asked this same question a couple days ago, but Chipmunk doesn't have any timer functionality in it. There are some Cocos2D users here, but you are much more likely to find somebody that knows how to use them on the Cocos2D forums.

Re: How to remove shape and body after a delay in collision call

Posted: Wed Nov 10, 2010 9:20 pm
by jason_rogers
Hi
I didn't answer in the previous thread because I thought scotts was enough
approach your problem this way:

the "delay" you want has nothing to do with chipmunk.

therefore what you want to do is:
- detect the collision you want
- save the cpShape that you'll want to remove.
- start a timer, count a certain number a frames, draw random numbers until you get on a predefined one ... however you want to handle your delay.
- when this delay has passed use a callback method to tirgger the cpSpaceAddPostStepCallback

and there you have removed your object with a delay.

I would draw your attention to the following point:

is this what you want to do with chipmunk, the situation you describes isn't very physically realistic. I mean its like you throw a tomato on a wall, it bounces off and then explodes ^^. I saw some cases like in angry birds where the birds rolls about on the floor after impact, but in general if you object is "dead" should it be interacting with the physics. In my case I had to launch animations after impact (little explosions) but I removed the object in post collision so that is looked like the object had flown straight through.

Re: How to remove shape and body after a delay in collision call

Posted: Sun Nov 14, 2010 12:33 pm
by muniraj_143
thanx for the reply