Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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

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 your wheel node in roughly the position of the back wheel.

  5. Drag out a Physics Pin Joint and pin the catapult to the back wheel. Your scene should now look like the following screenshot:

  6. To turn the pivot joint into a motor is as simple as clicking a tick...

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 $15.99/month. Cancel anytime
Visually different images