2011-07-14 10 views
0

私はこのような地上体を作成しています:BOX2D静体の摩擦

// Define the ground body. 
    b2BodyDef groundBodyDef; 
    groundBodyDef.position.Set(0, 0); // bottom-left corner 

    // Call the body factory which allocates memory for the ground body 
    // from a pool and creates the ground box shape (also from a pool). 
    // The body is also added to the world. 
    b2Body* groundBody = world->CreateBody(&groundBodyDef); 

    // Define the ground box shape. 
    b2PolygonShape groundBox; 

    // bottom 
    groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(screenSize.width/PTM_RATIO,0)); 
    groundBody->CreateFixture(&groundBox,0); 

    // top 
    groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width/PTM_RATIO,screenSize.height/PTM_RATIO)); 
    groundBody->CreateFixture(&groundBox,0); 

    // left 
    groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(0,0)); 
    groundBody->CreateFixture(&groundBox,0); 

    // right 
    groundBox.SetAsEdge(b2Vec2(screenSize.width/PTM_RATIO,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width/PTM_RATIO,0)); 
    groundBody->CreateFixture(&groundBox,0); 

私はそれが摩擦だ設定できますか?おかげさまで

答えて

1

特定の摩擦を設定できるフィクスチャ定義(b2FixtureDef)からフィクスチャを作成する必要があります。このような何か:

b2FixtureDef fixtureDef; 

fixtureDef.shape = &groundBox; 
fixtureDef.density = 0.0f; 
fixtureDef.friction = YOUR_FRICTION_VALUE; 

groundBody->CreateFixture(&fixtureDef); 
+0

はそれをしたと私はセマンティック問題を取得しています: /HelloWorldLayer.mm:エラー:セマンティック問題:互換性のない型から「constのb2Shape *」に割り当てる「b2BodyDef *」 – deMangoes

+0

私が編集しました私の答え、今それは動作するはずです。 Box2Dのドキュメントも参照してください:http://www.box2d.org/manual.html#_Toc258082968 – Oleg

関連する問題