Time for action – changing a b2Body fixture
All you have to do is make a call to body->DestroyFixture
. Not surprisingly, this should be done outside the simulation step.
- Inside the methods
makeCircleShape
andmakeBoxShape
in theEskimo
class, you will find these lines:if (_body->GetFixtureList() ) { _body->DestroyFixture(_body->GetFixtureList()); }
Here we just state that if there is a fixture for this body, destroy it. We can then switch from a box to a circle fixture when the player taps the screen, but use the same body throughout.
- We use this feature with platforms too. Platforms inside the pool that are not being used in the current level are set to inactive as follows:
_body->SetActive(false);
This removes them from the simulation.
- And when they are reinitialized to be used in a level, we destroy their existing fixture, update it to match the data from the
.plist
file, and set the body to active once again. This is how we do that://Define shape b2PolygonShape box...