Box2D Forums

It is currently Wed May 22, 2013 6:08 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sat May 07, 2011 8:21 am 
Offline

Joined: Sat May 07, 2011 8:02 am
Posts: 6
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


Top
 Profile  
 
PostPosted: Sun May 08, 2011 12:31 pm 
Offline

Joined: Tue Apr 26, 2011 11:00 pm
Posts: 6
Create the manager message


Top
 Profile  
 
PostPosted: Sun May 08, 2011 11:32 pm 
Offline

Joined: Sat May 07, 2011 8:02 am
Posts: 6
what is Create the manager message..

I don't know anything about it can u please tell me something about this


Top
 Profile  
 
PostPosted: Thu May 12, 2011 12:34 am 
Offline

Joined: Sat May 07, 2011 8:02 am
Posts: 6
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


Top
 Profile  
 
PostPosted: Fri May 13, 2011 2:38 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
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.


Top
 Profile  
 
PostPosted: Tue May 17, 2011 11:51 pm 
Offline

Joined: Sat May 07, 2011 8:02 am
Posts: 6
that was a great reply... irresistible force


Top
 Profile  
 
PostPosted: Sun Jun 19, 2011 8:56 pm 
Offline

Joined: Sat Jun 11, 2011 10:57 pm
Posts: 18
I had the same problem and this is what I did it works pretty well...

Code:
   
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


Top
 Profile  
 
PostPosted: Sun Aug 07, 2011 10:00 pm 
Offline

Joined: Thu Jun 30, 2011 10:02 pm
Posts: 2
I am face this problem.my problem is solve


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group