我有三个b2Body-s。头,下巴和一个静态b2Body。我将b2Joint从静态b2Body添加到头部,并将另一个b2Joint添加到头部和下巴。头部忽略静态物体,因为collideConnected对于关节为假,但下巴不忽略它。如何做到这一点?请建议。

最佳答案

enum CATEGORY_BITS
{
    BODY1_CATEGORY_BITS = 0x00000001,
    BODY2_CATEGORY_BITS = 0x00000002,
    BODY3_CATEGORY_BITS = 0x00000004,

};

当您创建实体时...
    b2FixtureDef fixtureForBODY1;
    fixtureForBODY1.shape = &shapeForBODY1;
    fixtureForBODY1.filter.categoryBits = BODY1_CATEGORY_BITS;
    fixtureForBODY1.filter.maskBits = BODY1_CATEGORY_BITS | BODY3_CATEGORY_BITS;


    b2FixtureDef fixtureForBODY2;
    fixtureForBODY2.shape = &shapeForBODY2;
    fixtureForBODY2.filter.categoryBits = BODY2_CATEGORY_BITS;
    fixtureForBODY2.filter.maskBits = BODY2_CATEGORY_BITS | BODY4_CATEGORY_BITS;

    b2FixtureDef fixtureForBODY3;
    fixtureForBODY3.shape = &shapeForBODY3;
    fixtureForBODY3.filter.categoryBits = BODY3_CATEGORY_BITS;
    fixtureForBODY3.filter.maskBits = BODY3_CATEGORY_BITS | BODY1_CATEGORY_BITS;

    b2FixtureDef fixtureForBODY4;
    fixtureForBODY4.shape = &shapeForBODY4;
    fixtureForBODY4.filter.categoryBits = BODY4_CATEGORY_BITS;
    fixtureForBODY4.filter.maskBits = BODY4_CATEGORY_BITS | BODY2_CATEGORY_BITS;



// BODY1 -> not collide connected (BODY2 and BODY4)
// BODY1 -> collide connected (BODY1 and BODY3)

关于iphone - 如何使b2Body忽略另一个b2Body?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15837813/

10-12 14:03