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
Learning iPhone Game Development with Cocos2D 3.0
Learning iPhone Game Development with Cocos2D 3.0

Learning iPhone Game Development with Cocos2D 3.0: Harness the power of Cocos2D to create your own stunning and engaging games for iOS

eBook
$17.99 $25.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning iPhone Game Development with Cocos2D 3.0

Chapter 2. Hello Cocos2D

We learned a bit about Cocos2D in the previous chapter, but it is now time to get our hands dirty and try it out in action. This chapter covers all the steps from installing Cocos2D to seeing your first Cocos2D game running. In addition to this, we're going to review Cocos2D distribution and will see some sample Cocos2D code in action.

In this chapter, we will complete the following tasks:

  • Downloading and installing Cocos2D
  • Creating and modifying our first Cocos2D project
  • Reviewing the contents of Cocos2D distribution
  • Running sample projects that come with Cocos2D

Starting with Xcode

Xcode is an Integrated Development Environment (IDE) created by Apple. It provides everything you need to create apps and games for iOS. In fact, you can even use Cocos2D to create apps and games for Mac OS X, but this is not covered in this book as we're going to concentrate on making games only for iOS.

We will use Xcode throughout this book for all of our projects, so if you don't have it installed yet, you should go and install it now. Downloading and installing Xcode will take some time, as it is about 2 GB; so, don't delay this and start installing it right away.

Don't worry, it won't cost you a dime. Yes, this great IDE from Apple is completely free and you can get it easily from the Mac App Store. To install Xcode, go to the Mac App Store (don't get confused with the iTunes App Store) and search for Xcode, or alternatively, you can just visit https://developer.apple.com/xcode/downloads/ and click on View on the Mac App Store.

Note

If...

Integrating Cocos2D with Xcode

We'll have to perform a small setup before we can use Cocos2D in our games. This won't require much of our time or a lot of complicated actions. We only need to download the Cocos2D installer from the official website and run it. The installer will integrate Cocos2D with Xcode and add new project templates and documentation.

Time for action – downloading and installing Cocos2D

We're going to install Cocos2D in three easy steps, which are as follows:

  1. Head over to http://www.cocos2d-iphone.org/download/ and download the installer of the latest stable version of Cocos2D.

    Note

    At the time of writing this book, Cocos2D Version 3.0.0 was the latest stable version and Version 3.1 was shortly to be released. However, most of the changes will not affect the code presented. They are mostly feature enhancements and performance optimizations. Also, the Cocos2D team stated that they will focus on the backwards compatibility with next releases, so you should be fine with any later version.

    However, keep in mind that even with all the developers' efforts trying to maintain the backwards compatibility, it is really hard to guarantee that the next versions will be fully backwards compatible. If you have any issues with the latest version, you can use the Chapter_02/Cocos2D+Installer+3.0.0.zip installer that comes...

Creating a Hello World project

I'm sure you're eager to create a project using the newly installed templates. Let's do this!

Time for action – creating a new project from a template

Before starting any serious project, let's create a very simple application using the newly installed Cocos2D templates, just to feel the taste of it. We'll do this using the following steps:

  1. Open Xcode and create a new project by navigating to File | New | Project. This will open the project creation dialog. In this dialog, you should see the new cocos2d v3.x category by navigating to iOS | cocos2d v3.x on the left of the screen. Refer to the following screenshot:
    Time for action – creating a new project from a template
  2. Go ahead and select the cocos2d iOS template. After this, click on the Next button.
  3. Let's fill out the required information. Enter HelloWorld for the Product Name and fill out the Organization Name and the Company Identifier fields as you like. The following is how I filled out the information in this dialog:
    Time for action – creating a new project from a template

    Filling out the project options

    Note

    Right now, you can enter anything in these fields, just to keep Xcode happy. However, when you want to actually...

Time for action – running the project on the simulator

The project generated using Cocos2D already contains some code that we can see in action, so let's make sure that Xcode is targeting the simulator and run the project, before making any changes. To do this, perform the following steps:

  1. Switch to Xcode and take a look at the top-left corner of the Xcode window, as shown in the following screenshot:
    Time for action – running the project on the simulator
  2. Click on the iPhone label marked with the black square as shown in the previous screenshot. It will open a drop-down list similar to what is shown in the following screenshot:
    Time for action – running the project on the simulator
  3. Here, we can see the different simulators we can run our project on. Let's select iOS 7.1 by navigating to iPhone Retina (4-inch) | iOS 7.1 and click on the Run button (command + R).

    Note

    If you don't see some of the simulator versions in this drop-down list, you just don't have them installed. To install additional simulators, navigate to Xcode | Preferences and select the Downloads tab in the...

Starting with Xcode


Xcode is an Integrated Development Environment (IDE) created by Apple. It provides everything you need to create apps and games for iOS. In fact, you can even use Cocos2D to create apps and games for Mac OS X, but this is not covered in this book as we're going to concentrate on making games only for iOS.

We will use Xcode throughout this book for all of our projects, so if you don't have it installed yet, you should go and install it now. Downloading and installing Xcode will take some time, as it is about 2 GB; so, don't delay this and start installing it right away.

Don't worry, it won't cost you a dime. Yes, this great IDE from Apple is completely free and you can get it easily from the Mac App Store. To install Xcode, go to the Mac App Store (don't get confused with the iTunes App Store) and search for Xcode, or alternatively, you can just visit https://developer.apple.com/xcode/downloads/ and click on View on the Mac App Store.

Note

If you have an Xcode version prior...

Integrating Cocos2D with Xcode


We'll have to perform a small setup before we can use Cocos2D in our games. This won't require much of our time or a lot of complicated actions. We only need to download the Cocos2D installer from the official website and run it. The installer will integrate Cocos2D with Xcode and add new project templates and documentation.

Time for action – downloading and installing Cocos2D


We're going to install Cocos2D in three easy steps, which are as follows:

  1. Head over to http://www.cocos2d-iphone.org/download/ and download the installer of the latest stable version of Cocos2D.

    Note

    At the time of writing this book, Cocos2D Version 3.0.0 was the latest stable version and Version 3.1 was shortly to be released. However, most of the changes will not affect the code presented. They are mostly feature enhancements and performance optimizations. Also, the Cocos2D team stated that they will focus on the backwards compatibility with next releases, so you should be fine with any later version.

    However, keep in mind that even with all the developers' efforts trying to maintain the backwards compatibility, it is really hard to guarantee that the next versions will be fully backwards compatible. If you have any issues with the latest version, you can use the Chapter_02/Cocos2D+Installer+3.0.0.zip installer that comes with this book...

Creating a Hello World project


I'm sure you're eager to create a project using the newly installed templates. Let's do this!

Time for action – creating a new project from a template


Before starting any serious project, let's create a very simple application using the newly installed Cocos2D templates, just to feel the taste of it. We'll do this using the following steps:

  1. Open Xcode and create a new project by navigating to File | New | Project. This will open the project creation dialog. In this dialog, you should see the new cocos2d v3.x category by navigating to iOS | cocos2d v3.x on the left of the screen. Refer to the following screenshot:

  2. Go ahead and select the cocos2d iOS template. After this, click on the Next button.

  3. Let's fill out the required information. Enter HelloWorld for the Product Name and fill out the Organization Name and the Company Identifier fields as you like. The following is how I filled out the information in this dialog:

    Filling out the project options

    Note

    Right now, you can enter anything in these fields, just to keep Xcode happy. However, when you want to actually publish your game in...

Time for action – running the project on the simulator


The project generated using Cocos2D already contains some code that we can see in action, so let's make sure that Xcode is targeting the simulator and run the project, before making any changes. To do this, perform the following steps:

  1. Switch to Xcode and take a look at the top-left corner of the Xcode window, as shown in the following screenshot:

  2. Click on the iPhone label marked with the black square as shown in the previous screenshot. It will open a drop-down list similar to what is shown in the following screenshot:

  3. Here, we can see the different simulators we can run our project on. Let's select iOS 7.1 by navigating to iPhone Retina (4-inch) | iOS 7.1 and click on the Run button (command + R).

    Note

    If you don't see some of the simulator versions in this drop-down list, you just don't have them installed. To install additional simulators, navigate to Xcode | Preferences and select the Downloads tab in the opened dialog.

    It will take some...

Modifying the project


We're going to create a new view from scratch and will display it instead of the view with the Hello World label generated by the Cocos2D template.

Left arrow icon Right arrow icon

Description

This book is an easy-to-follow, step-by-step beginner's guide covering the full process of creating a game. It is packed with examples and illustrations, with comprehensive coverage of each topic. If you want to learn how to make games using the Cocos2D framework, this book is for you. If you would like to build a good foundation for a career in game development as an independent game developer or at a game studio, or if you just want to make games as a hobby, then you'll love this book. You should have some basic programming experience with Objective-C and Xcode. To run the code in this book, you will also need an Intel-based Macintosh running OS X Mountain Lion (or later).

What you will learn

  • Install Cocos2D and create projects using Cocos2D Xcode templates
  • Understand the Cocos2D architecture and its main classes
  • Render images and text, move and animate them
  • Control your game using touches and a gyroscope
  • Create a user interface and navigate between game screens
  • Use the physics engine to apply forces and detect collisions
  • Add sounds and music and change playback properties
  • Integrate your game with Game Center and make InApp purchases

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 25, 2014
Length: 434 pages
Edition : 1st
Language : English
ISBN-13 : 9781782160151
Vendor :
Apple
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 25, 2014
Length: 434 pages
Edition : 1st
Language : English
ISBN-13 : 9781782160151
Vendor :
Apple
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 147.97
Learning Cocos2d-x Game Development
$48.99
Learning iPhone Game Development with Cocos2D 3.0
$43.99
Cocos2d Game Development Blueprints
$54.99
Total $ 147.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. All About Cocos2D Chevron down icon Chevron up icon
2. Hello Cocos2D Chevron down icon Chevron up icon
3. Cocos2D – Under the Hood Chevron down icon Chevron up icon
4. Rendering Sprites Chevron down icon Chevron up icon
5. Starting the Action Chevron down icon Chevron up icon
6. Rendering Text Chevron down icon Chevron up icon
7. Animations and Particle Systems Chevron down icon Chevron up icon
8. Adding Sound Effects and Music Chevron down icon Chevron up icon
9. User Interface and Navigation Chevron down icon Chevron up icon
10. Physics Chevron down icon Chevron up icon
11. Working with Tile Maps Chevron down icon Chevron up icon
A. Pop Quiz Answers Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(9 Ratings)
5 star 66.7%
4 star 33.3%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Aug 19, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you’re new to iOS game development now is a great time to get started. In 2008 a brilliant engineer named Ricardo Quesada rewrote his 2D game engine for Apple’s iOS and released it as open source. It’s no exaggeration to say that hundreds of games, like my own, were developed using Cocos2D—including dozens of hits. Now it’s 2014 and the newbie game developer has several versions of Quesada’s Cocos2D framework to choose from. But for me the branch of Cocos2D devoted to the iPhone and iPad will always have a special place in my heart. Clearly Cocos2D-iPhone (now called Cocos2D-Swift) was the inspiration for Apple’s SpriteKit framework. And once you learn the fundamentals of Cocos2D on iOS you can easily transfer these skills to Android, Windows, and HTML5 versions of the Cocos2d family. Working with Cocos2d-Swift is like “reading Shakespeare in the original Klingon.”Learning iPhone Game Development with Cocos2d 3.0 by Kirill Muzykov is a book I wish I had when I was learning to develop my first iPhone game. Muzykov patiently covers all the basics (nodes, sprites, actions, text, sound, buttons, menus) and jumps into advanced topics (particles, physics, tile maps, iTunesConnect, Game Center, and in-app purchases) while guiding the reader though creating a game called CocosHunt and using important tools (Particle Designer, Texture Packer, Tiled) and websites (freesound.org, media.io).Along the way the reader also learns about Objective-C, Xcode, and iOS APIs. You’re still a beginner by the time you finish Muzykov’s book but you’re a well informed beginner and ready to tackle larger and more complex projects—like the next Candy Crush.One of the best things I like about Muzykov’s book is it’s structure. A typical chapter starts with setting up a project and cycles through segments entitled “time for action” and “what just happened?”. This alternating rhythm becomes a reliable way to digest the material and ensure the author doesn’t wave his hands over new concepts. Almost every chapter includes a pop-quiz. I’m not a big fan of quizzes but if that’s what you need to re-enforce the material Muzykov provides them.The source code is clean and clearly written with good comments. Muzykov keeps the syntax simple, using “typedef enum” instead of “typedef NS_ENUM” and “#define” instead of “FOUNDATION_EXPORT NSString *const” which is probably for portability. Much of a game is managing state and game developer who follow Muzykov examples in his classes won’t get into trouble.If you’re new to mobile game development and you want to focus on iOS then Learning iPhone Game Development with Cocos2d 3.0 is a good book for you.
Amazon Verified review Amazon
Amazon Customer Jul 31, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I started learning Cocos2d last year, and struggled because the books and tutorials I was coming across were outdated. This book takes care of that, covering Cocos2d v3 which is the latest version right now. I found the teaching on caching sounds, developing levels for retina/non-retina displays and UI layout most interesting. Additionally you'll learn how to use tools such as TexturePacker to handle assets in the game. This is a big deal, as a lot of time can be wasted as you are learning if you don't have a good book like this one on hand! My only regret with this book is that it was not around when I first started last year, as it would have saved me a ton of time!
Amazon Verified review Amazon
R.B. Aug 06, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
When a book normally starts with "its for everyone with no experience in game development and basic Objective-C skills"i get sceptic. But "Learning iPhone Game Development with Cocos2d 3.0" from Kirill Muzykov is a really rare exception of that.I was fascinated by the way the book explains all the details from sprites over physics to Tile Maps in an easy way. Addedwith great illustrations and simple, effective code. And all this on a game called "Hunter" which is a refreshing differenceto examples used in other books i read, because of it's "real world" character.The book is also full of hints (like debugging and understand FPS), side informations (like types of animation)and quiz like questions to test the reader 's knowledge about each chapter.I really wished this book was available when i start learning Cocos2D 3 years ago.From my side a clear 5 star review (the first time i give this for a book).
Amazon Verified review Amazon
tuomojau Jul 17, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
At the moment this book is one of the best books written of Cocos2d (and the most up-to-date with covering the v 3.0) It’s organized around the development of one single game through the whole book, which makes it clear and easy to follow. It gives a good view of everything that can be done with Cocos2d. I imagine that for beginners this is a must book, but also if one has some experience with Cocos2d this book has a lot of tricks and tips how to improve the code.
Amazon Verified review Amazon
Branislav Siarsky Feb 22, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well written, logical, covering all must know aspects. After reading I was able to at least put my sprites in the desired order :)
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.