如何使b2Body忽略另一个b2Body?

时间:2013-04-05 15:29:58

标签: iphone ios cocos2d-iphone box2d box2d-iphone

我有三个b2Body-s。头部,下巴和一个静态型b2Body。我从静态b2Body添加一个b2Joint到头部,另一个b2Joint用于头部和下巴。头部忽略静态体,因为collideConnected对于关节是假的,但是下巴不会忽略它。怎么做到这个?请建议。

1 个答案:

答案 0 :(得分:1)

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)