Alisa
Alisa

Reputation: 23

Remove b2body from cocos2d sprite

Is there a way to remove b2body associated with a sprite? The sprite should appear on screen but with out physics.

I am using cocos2d Box2d.

Upvotes: 0

Views: 241

Answers (1)

Renaissance
Renaissance

Reputation: 554

We give sprite as userdata of the b2body. So if you want to remove the body which has specific sprite as a userdata then you have to go through all the body which are at moment present in world and then one by one compare with them and if you find that then remove that corresponding body. let say you want to delete the body corresponding to CCSprite* temp;

for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {
if (b->GetUserData() != NULL) {
            CCSprite *sprite = (CCSprite *)b->GetUserData();     
            if (sprite==temp) {
               world->destroyBody(b);
               break;
            }
}

Upvotes: 1

Related Questions