3

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;
}
4

2 に答える 2

2

box2dです。新しいバージョンでは、b2EdgeShapeというクラスがあり、Set()というメソッドがあると思います。ポリゴンシェイプとその非推奨のsetEdgeメソッドの代わりにそれを使用できます。

http://www.box2d.org/manual.html

セクション4.5を参照

于 2012-01-19T02:59:44.967 に答える
2

新しいCocos2D+Box2Dサンプルプロジェクトがどのようにそれを行うかを確認できます。

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);
于 2012-01-19T23:04:02.453 に答える