Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Cocos2d Game Development Essentials

You're reading from   Cocos2d Game Development Essentials For new users - a quickstart guide to bringing your mobile game ideas to life with Cocos2D

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781784390327
Length 136 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ben Trengrove Ben Trengrove
Author Profile Icon Ben Trengrove
Ben Trengrove
Arrow right icon
View More author details
Toc

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 node and set the two bodies on the node to be between the invisible node and the catapult arm.

  4. Build and run your game; your catapult arm should not fall down now.

You will tune the values of the spring joint later when you can test out the dragging...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image