0
votes

using cocos2d and box2d i am taking a body and put a sprite that follow him, now i would like to see not only the sprite but the whole world bodies shapes(boxs,and circles) to understand better my world physics.

the sprite follow a body with :

    world->Step(dt,10,10);
    for(b2Body *b=world->GetBodyList(); b; b=b->GetNext()) // b is the list of all bodys in the world and we running on them 
    {
        if(b->GetUserData() !=NULL )
    {
        CCSprite *sprite=(CCSprite *) b->GetUserData();//every b of the world will be update his position
        sprite.position=ccp( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO  ) ;
        sprite.rotation=-1*CC_RADIANS_TO_DEGREES(b->GetAngle());
    }

}

how would i do that? is it require a big code ?

thanks a lot.

1

1 Answers

2
votes

Use b2DebugDraw. Here is the code how do it:

http://www.ccsprite.com/box2d/debugdraw-box2d-cocos2d.html

That will automatically draw your b2World.