How to implement a bomb explosion in Box2D iphone?

By | January 30, 2011

Below code is a simplest way to do that.

-(void) explodeBomb
    {
        b2Vec2 force = b2Vec2(0.25,0.70); // give the direction for the force.
        bombBody->ApplyLinearImpulse(force, bombBodyDef.position);
        CCSprite *sp = (CCSprite *) bombBody->GetUserData();
        sp.opacity = 0; // setting the sprite in the body opacity to zero.
        [self schedule:@selector(destroyBomb) interval:2]; //destroying bombBody after 2 sec.
    }
    -(void) destroyBomb
    {
        CCLOG(@"Destroying Bomb");
        world->DestroyBody(bombBody);
    }

2 thoughts on “How to implement a bomb explosion in Box2D iphone?

Leave a Reply

Your email address will not be published. Required fields are marked *