在cocos2d版本v1.0.1中
groundBox.SetAsEdge(left,right);
需要避免使用SetAsEdge方法,因为该方法已在之前的版本中被删除,因此会出现错误提示该方法不存在。
但我不确定如何做到这一点,因为它不是创建一个盒子,我也不确定它是通过使用顶点数组来创建多条线段(根据我的理解),如何使用新的方法实现。
- (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;
}