I am new in Box2d and learning myself. I am learning Box2d from here
I want to make a body and want to give b2body a angle so that it will look like body is stand like skew line, like slope.
This is my code.
for(int i = 0; i < 4; i++) {
static int padding=20;
// Create block and add it to the layer
CCSprite *block = [CCSprite spriteWithFile:@"slope.png"];
int xOffset = padding+block.contentSize.width/2+ ((block.contentSize.width+padding)*i);
block.position = ccp(xOffset, 250);
block.tag = 2;
[self addChild:block];
// Create block body
b2BodyDef blockBodyDef;
blockBodyDef.type = b2_staticBody; //b2_dynamicBody
blockBodyDef.position.Set(xOffset/PTM_RATIO, 250/PTM_RATIO);
blockBodyDef.userData = block;
b2Body *blockBody = _world->CreateBody(&blockBodyDef);
// Create block shape
b2PolygonShape blockShape;
blockShape.SetAsBox(block.contentSize.width/PTM_RATIO/2,
block.contentSize.height/PTM_RATIO/2);
// Create shape definition and add to body
b2FixtureDef blockShapeDef;
blockShapeDef.shape = &blockShape;
blockShapeDef.density = 10.0;
blockShapeDef.friction = 0.0;
blockShapeDef.restitution = 0.1f;
blockBody->CreateFixture(&blockShapeDef);
}
In this code I made 4 b2body horizontically. Now I want these in vertical and slightly skew, like a slope.
I am not able to do this yet.
I dont know I have to give angel to the body or something else. Not able to find sample code and good tutorials of Box2d.
Is there any site available where I can find some xcode Box2d demo for beginners? Or some code like applications we have UIButtons, UILabel, UITextfiled programatically, can I find Box2d codes like this?
In this demo I am trying to make 4 static slope image and from the left upper side corner I have to push ball(b2dynamicbody). The ball will go through these 4 static body and the ball will turn according to the slope.
Any Idea or suggestions would be highly welcome.