Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 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;
    box...