Box2d Physics Sprite removal

I guess I might be missing something obvious here, but I had problem removing a Box2d Physics sprite.  I had assumed removing the Physics sprite from the parent removed the physics body as well, but it doesn't, so you get an invisible thing on the screen that other physics objects can still bump into.

For various reason I'm using a mix of PhysicsSprites and CCSprites - with PhysicsSprite being the class defined in the Cocos2d template.  I'm doing my own collision detection between the non-physics sprites and PhysicsSprite (this is probably a bad idea...).

I had to extend PhysicsSprite to add:

-(b2Body*) getPhysicsBody;
return body_;

so I  could get the body,  and then I could remove the PhysicsSprite like this:

        PhysicsSprite * block = [self getChildByTag:blockTag];
        b2Body *body = block.getPhysicsBody;
       [self removeChild:block cleanup:YES];

I'm still got a feeling I'm missing something, but this seems to work...

No comments:

Post a Comment