O'Reilly logo

Cocos2D Game Development Essentials by Ben Trengrove

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a motor

A great feature of joints is that they can be turned into a motor. A joint can be given a rate of rotation that can be used to propel objects through the scene. This can be used to add objects that behave like vehicles in your game.

To demonstrate this, you will modify your catapult to drive into your structure instead of throwing objects at it. This can all be done within SpriteBuilder. Following are the steps:

  1. Open up your project in SpriteBuilder and drag out a CCColorNode onto the scene.
  2. Make sure it is a child of the physics node. This will be the wheel for your catapult, so resize it appropriately.
  3. Enable physics on the node. Change the physics shape to be a Circle, the density to 10.00, and the friction to 1.00.

  4. Position

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required