Game Development Reference
In-Depth Information
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.
1. Inside the methods makeCircleShape and makeBoxShape in the Eskimo
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.
2. 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.
3. And when they are reinitialized to be used in a level, we destroy their existing fix-
ture, 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;
box.SetAsBox(width * 0.5f /PTM_RATIO, PLATFORM_HEIGHT
* 0.5f / PTM_RATIO);
//Define fixture
b2FixtureDef fixtureDef;
fixtureDef.shape = &box;
fixtureDef.density = 1;
fixtureDef.restitution = 0;
//reutilize body from the pool: so destroy any
Search WWH ::




Custom Search