cocos2d iphone - saving contact bodies to be destroyed -


in code destroy 1 of 2 contacted bodies. within begincontact following method in ccphysicssprite called:

-(void)contactmade:(ccphysicssprite*)contactedsprite { int spritetag1 = self.tag; int spritetag2 = contactedsprite.tag;  if (((spritetag1 == 3) && (spritetag2 == 4)) || ((spritetag1 == 4) && (spritetag2 == 3)) {     ccphysicssprite* herosprite = (ccphysicssprite*)[self getchildbytag:4];     b2world* world;      world->destroybody(herosprite.b2body);     herosprite.b2body = null;     [herosprite.parent removechild:herosprite]; } 

i signal sigabrt pointing

b2assert(m_bodycount > 0); 

after searching on issue. read contact body has saved , destroyed after timestep. how can this, given have set contact conditions in ccphyscissprite.

you can add flag ( : isdead ... ) physical object , in collision event change flag value true .

-(void) collisionbegin:(b2fixture*)target with:(b2fixture*) source {         if ( target->getbody()->gettype() == b2_dynamicbody)     {         yourcustomclass *temp = (yourcustomclass *)target->getbody()->getuserdata();         temp->isdead = true ;     } } 

then in update function after step physical world's object , find specific object flag ( here : isdead ) , , destroy .

-(void) update: (cctime) dt {      int32 velocityiterations = 8;     int32 positioniterations = 3;      world->step(dt, velocityiterations, positioniterations);      // remove box2d object here , after step function      ( b2body *b = world->getbodylist(); b; )     {         b2body *baba = b->getnext();         if ( b->getuserdata() != null && b->gettype() == b2_dynamicbody)         {             yourcustomclass *t = (yourcustomclass *)b->getuserdata();             if ( t->isdead )             {                 world->destroybody(b);    // remove physical body                 [self removechild:t];     // remove node super layer             }         }         b = baba ;     } } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -