1
votes

i use cocos2d-iphone-0.99.2 and integrated in it box2d. i have 2 kind of sprites with tags 1 and 2. Also i created bodies and shape definitions for them. what i'm trying to do is to make sprite1 kinds to act as solid or act as not solid when sprite2 colides with them. i tried this code :

for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) 
{    
  if (b->GetUserData() != NULL) 
    {
      CCSprite *sprite = (CCSprite *)b->GetUserData();     
        if (sprite.tag == 1) 
        {
            b2Fixture* f = b->GetFixtureList();
            f->SetSensor(solid);
        }
    }
}

Where solid is bool. The first time when i change fixture to sensor everything is just fine but when i try to revert and change again to solid my app crashes with the following error : Assertion failed: (manifold->pointCount > 0), function b2ContactSolver, file /Documents/myapp/libs/Box2D/Dynamics/Contacts/b2ContactSolver.cpp, line 58.

Is it possible somehow to change fixture->SetSensor several times and if so ... how ? Any help is highly appreciated.

1
Found workaround - to destroy all kinds of sprites with tags 1, also destroy and recreate their bodies fixtures and joints and then set their fixtures to Sensor or not. Still searching for solution to do this dynamically without need to destroy and recreate.Asen

1 Answers

1
votes

Well ... the answer is that fixtures are kept in arrays so if u have just 1 fixture per body changing it will look like :

for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()){if (b->GetUserData() != NULL) 
{
  CCSprite *sprite = (CCSprite *)b->GetUserData();     
    if (sprite.tag == 1) 
    {
        b2Fixture* f = b->GetFixtureList();
        f[0]->SetSensor(solid);
    }
}

}