Working with joints
In Box2d, joints are used to connect two bodies so that each body is in some way attached to the other. The various types of joints make it possible to customize our characters, vehicles, and the world. Furthermore, joints can be created and destroyed during a simulation, which gives us endless possibilities for our games. In this recipe, we will create a line joint to demonstrate how joints are set up and used in the physics world.
Getting ready...
Create an activity following the steps in the Introduction to the Box2D physics extension section given at the beginning of the chapter. This activity will facilitate the creation of two bodies and a connecting line joint that we will use for this recipe. Refer to the JointsActivity
class in the supplemental code for examples of more types of joints.
How to do it...
Follow these steps to create a line joint:
Define the following variables within our activity:
Body LineJointBodyA; Body LineJointBodyB; final FixtureDef boxFixtureDef...