cocos2d-iphonebox2dbox2d-iphone

Removing a body with box2D


I need to remove a certain vector from my world bounds, for example only the left one. (box2d+cocos2d iphone)

This is how I set the bounds:

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);

How can I remove the left one ONLY?

I know this :

screenBorderBody->DestroyFixture(b2Fixture *fixture)

But I need to do that later on, so can I reach that fixture (having the body pointer) without saving this specific one as a global?

Thanks.


Solution

  • screenBorderShape.Set(lowerRightCorner, upperRightCorner); screenBorderBody->CreateFixture(&screenBorderShape, 0);

    Name this fixture as left fixture or left wall....

    After this you can use screenBorderBody->DestroyFixture(<#b2Fixture *fixture#>)

    ...

    The way is

    groundBox.Set(b2Vec2(X1/PTM_RATIO,Y1/PTM_RATIO), b2Vec2(X2/PTM_RATIO, Y1/PTM_RATIO)); bottomFixture = groundBody->CreateFixture(&groundBoxDef);

    and then remove bottom fixture (left in your case)

    In caseyou just want to cancel the collisions do it by setting category or mask bits that way