Combining two or more joints can create some interesting effects. In this example, we will create a car that can be driven around a level.
Please refer to the project RecipeCollection02 for full working code of this recipe. Also note that some of the following code has been omitted for brevity.
@implementation Ch4_Vehicles -(CCLayer*) runRecipe { [super runRecipe]; [message setString:@"Press and hold to drive car."]; //Initialization pressedLeft = NO; pressedRight = NO; //Create level [self createLevel]; //Add taxi [self addTaxi]; return self; } -(void) createLevel { /* Create a sine wave road for our car */ b2BodyDef groundBodyDef; groundBodyDef.position.Set(0, 0); b2Body *body = world->CreateBody(&groundBodyDef); b2PolygonShape groundBox; b2FixtureDef groundFixtureDef; groundFixtureDef.restitution = 0.0f; groundFixtureDef.friction = 10.0f; //The road has a lot of friction...