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 Blueprints

You're reading from   Cocos2d Game Development Blueprints Design, develop, and create your own successful iOS games using the Cocos2d game engine

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781783987887
Length 440 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Jorge Jord√°n Jorge Jord√°n
Author Profile Icon Jorge Jord√°n
Jorge Jord√°n
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Sprites, Sounds, and Collisions 2. Explosions and UFOs FREE CHAPTER 3. Your First Online Game 4. Beat All Your Enemies Up 5. Scenes at the Highest Level 6. Physics Behavior 7. Jump and Run 8. Defend the Tower Index

Creating sprites with physics


If you thought that the only way to view bodies was using the debug draw mode, you were wrong. In the current version of Cocos2d, CCNode has a property called physicsBody where we can link a physical body to the node.

This feature makes it as easy to create a sprite that responds to physical stimulations as declaring a common sprite and setting the CCPhysicalBody instance to it. Let's prove this with an example.

We are going to create a star, so paste the following lines in the variables declaration section in GameScene.m:

    // Declare a sprite
    CCSprite *_star;

We want the star to have an image so:

  1. In the project navigator, select the Resources group.

  2. Right-click and select Add Files to "SnookerMunk"….

  3. Look for the star.png file in the Resources folder you unzipped.

  4. Be sure that Copy items into destination group's folder (if needed) is selected and click on Add.

Now add the following lines at the end of the init method just before return self;:

    // Initialize...
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