iphone - BOX2D 静态体摩擦

标签 iphone c++ objective-c cocoa-touch 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);

如何设置它的摩擦力? 谢谢。

最佳答案

您需要根据夹具定义 (b2FixtureDef) 创建夹具,您可以在其中设置特定的摩擦力。像这样:

b2FixtureDef fixtureDef;

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

groundBody->CreateFixture(&fixtureDef);

关于iphone - BOX2D 静态体摩擦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6695228/

相关文章:

ios - 单个 iPhone 应用程序中可设置的最大 NSTimer 数

c++ - 无法为 swig python 设置 QuantLib

c++ - 如何确定用户输入的是字符串中的数字

iPhone UnitTesting UITextField 值和测试错误 133

ios - 在 iOS 设备上本地保存解析对象

iphone - 需要 Objective-C 设计帮助,可能需要协议(protocol)?

ios - 由于 ios 中未捕获的异常 'NSUnknownKeyException' 而终止应用程序

c++ - 加载/卸载时由共享库执行的代码

Objective-C 协议(protocol)静态方法?

iphone - CATransition 显示动画开始之前过渡结束时的单个帧