I'm using code from the Box2D template application of Cocos2d 0.99.2.
Here’s my code:
//Set up a 1m squared box in the physics world
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(playerSprite.position.x/PTM_RATIO, playerSprite.position.y/PTM_RATIO);
bodyDef.userData = playerSprite;
b2Body *body = world->CreateBody(&bodyDef);
// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(0.5f, 1.0f);//These are mid points for our 1m box
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body->CreateFixture(&fixtureDef);
But when I run the app, the "dynamicBox" appears as a grey box behind my sprite (which is a transparent PNG). See this screenshot (http://dl.dropbox.com/u/103936/Screen%20shot%202010-04-27%20at%2011.52.19%20PM.png). How do I fix this?
Thanks in advance! This is a great community.