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

Adding a sprite joint

Now, the catapult at least holds itself together, but it is not the greatest structure ever created. The arm instantly falls down. What you want is the arm to stay up and then be able to be dragged backwards.

To achieve this behavior, you will use the Physics Spring Joint. The question however is what are you joining it to? Perform the following steps:

  1. You need to hook up your arm to an invisible object that is above the catapult, which will hold the arm up. As this is a spring, which will allow the arm to be pulled in different directions and spring back.
  2. Add a blank CCNode as a child of the physics node. This node will have no size. Click on Enable physics for the node and set it to be Static.
  3. Now, drag out a physics spring ...

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