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

Dragging an object against a spring joint


In order to drag our catapult arm back, we will create another joint. However, this joint will be between our finger and the catapult arm. As you can't create a joint to your finger, what you will do is create another empty node that will move based on touch. This empty node will be joined to the catapult arm. Following are the steps:

  1. Create a new empty node as in the last section. Enable physics and set it to static. The position of the node does not matter as it will be moved in code, but you must ensure that it is a child of the physics node. Add a code connection called _touchNode to the new node.

  2. You will also need a code connection for the catapult arm. Call it _catapultArm.

  3. Add another code connection for the physics node: _physicsNode.

  4. You will do this section in code. Switch over to Xcode.

  5. First, add the property implementation for your new code connection. Also, add another property for the new joint that will be created in code:

    @interface MainScene...
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