Creating multiple-fixture bodies
We sometimes need a body that has varying physics attributes on certain parts of it. For instance, a car with a bumper should react differently if it hits a wall to a car without a bumper. The creation of such a multifixture body in Box2D is fairly simple and straightforward. In this recipe, we will see how to create a multifixture body by creating two fixtures and adding them to an empty body.
Getting ready...
Follow the steps in the Introduction to the Box2D physics extension section at the beginning of the chapter to create a new activity that will facilitate the creation of our multifixture body.
How to do it...
Follow these steps to see how we can create multifixture bodies:
Place the following code in the
onPopulateScene()
method to create two rectangles that have a modifiedAnchorCenter
value which allows for precise placement when linked to a body:Rectangle nonbouncyBoxRect = new Rectangle(0f, 0f, 100f, 100f, this.getEngine().getVertexBufferObjectManager...