In cocos2d version v1.0.1
groundBox.SetAsEdge(left,right);
It needs to not use the SetAsEdge as an error saying that the method doesn't exist, which makes sense as it was removed in a previous version However I'm unsure of how to do this as its not creating a box and I'm unsure instead its creating multiple lines using an array of vertexs (from my understanding) how do I do it using the new
- (void)createGroundEdgesWithVerts:(b2Vec2 *)verts numVerts:(int)num
spriteFrameName:(NSString *)spriteFrameName {
CCSprite *ground =
[CCSprite spriteWithSpriteFrameName:spriteFrameName];
ground.position = ccp(groundMaxX+ground.contentSize.width/2,
ground.contentSize.height/2);
[groundSpriteBatchNode addChild:ground];
b2PolygonShape groundShape;
b2FixtureDef groundFixtureDef;
groundFixtureDef.shape = &groundShape;
groundFixtureDef.density = 0.0;
// Define the ground box shape.
b2PolygonShape groundBox;
for(int i = 0; i < num - 1; ++i) {
b2Vec2 offset = b2Vec2(groundMaxX/PTM_RATIO +
ground.contentSize.width/2/PTM_RATIO,
ground.contentSize.height/2/PTM_RATIO);
b2Vec2 left = verts[i] + offset;
b2Vec2 right = verts[i+1] + offset;
groundShape.SetAsEdge(left,right);
groundBody->CreateFixture(&groundFixtureDef);
}
groundMaxX += ground.contentSize.width;
}
It is box2d. In the newer version I believe there is a class called b2EdgeShape and it has a method called Set() You could use that instead of the polygon shape and its deprecated setEdge method.
http://www.box2d.org/manual.html
See section 4.5
You could check how the new Cocos2D+Box2D sample project does it.
Here's how I create a screen-sized box in Kobold2D:
// for the screenBorder body we'll need these values
CGSize screenSize = [CCDirector sharedDirector].winSize;
float widthInMeters = screenSize.width / PTM_RATIO;
float heightInMeters = screenSize.height / PTM_RATIO;
b2Vec2 lowerLeftCorner = b2Vec2(0, 0);
b2Vec2 lowerRightCorner = b2Vec2(widthInMeters, 0);
b2Vec2 upperLeftCorner = b2Vec2(0, heightInMeters);
b2Vec2 upperRightCorner = b2Vec2(widthInMeters, heightInMeters);
// Define the static container body, which will provide the collisions at screen borders.
b2BodyDef screenBorderDef;
screenBorderDef.position.Set(0, 0);
b2Body* screenBorderBody = world->CreateBody(&screenBorderDef);
b2EdgeShape screenBorderShape;
// Create fixtures for the four borders (the border shape is re-used)
screenBorderShape.Set(lowerLeftCorner, lowerRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(lowerRightCorner, upperRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(upperRightCorner, upperLeftCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(upperLeftCorner, lowerLeftCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With