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
Explore 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
Cocos2d Game Development Essentials
Cocos2d Game Development Essentials

Cocos2d Game Development Essentials: For new users - a quickstart guide to bringing your mobile game ideas to life with Cocos2D , Second Edition

eBook
AU$14.99 AU$36.99
Paperback
AU$45.99
Subscription
Free Trial
Renews at AU$24.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

Cocos2d Game Development Essentials

Chapter 2. Nodes, Sprites, and Scenes

In the last chapter, you went through the introduction of Cocos2d template. You had a look at your first nodes, and sprites, and learned how to move between scenes. In this chapter, you will get into more detail on how these elements work and what can be done with them. You will also create your first mini game to begin with, to see how the pieces all come together.

In this chapter, you will learn:

  • How to build blocks of Cocos2d nodes
  • How to display images on the screen
  • How to layout your scene
  • How to change between different scenes

The building blocks, nodes

In Cocos2d, everything you see on screen is a subclass of the CCNode class. Even the scenes your game has are subclasses of the CCNode class.

There are some important subclasses that will be used in almost every game. Therefore, it is important to know them. These are as follows:

  • CCSprite: This represents an image that can be animated
  • CCNodeColor: This is a plain colored node
  • CCLabelTTF: This is a node that renders text in any TrueType font
  • CCButton: This is an interactive node that can have an action attached
  • CCLayoutBox: This is a node that lays out other nodes in a vertical or horizontal layout

Tip

The CCLayoutBox node replaces the CCMenu class, which was in the previous versions of Cocos2d.

The reason every class inherits from the CCNode class is that there are some important properties that all visible elements on-screen need. These are as follows:

  • contentSize: This is the size of the element in the unit that is specified in the contentSizeType property
  • position: This...

Putting it into practice

It's now time to start working on your first game. You will put all the information you have learned so far into practice, and create a very simple game using nodes and sprites. The game will be a simple one where you try to catch water in a bucket. The game will get faster and faster as it goes on. It's probably not going to make you the next App Store millionaire, but you have to start somewhere right?

Here is what our game will look like when it is finished:

Putting it into practice

Start by making a new Cocos2d project in Xcode just like you did in the last chapter. You can also delete the HelloWorldScene classes as you won't be using them.

Open up the IntroScene.m file, and delete all the code from the init method, except the required initialization and return statement. Also, you can delete the onSpinningClicked method. You should end up with an implementation, as shown in the following code:

@implementation IntroScene

// ----------------------------------------------...

The next step

Congratulations on making your first game in Cocos2d. There are many possible extensions you could make:

  1. The game currently only drops one drop at a time. It was set up to use an array for drops; however, you should be able to easily drop more than one drop at once.
  2. Currently the drop falls behind the water bucket; this is not what the designer intended. Modify the game so the drop falls into the bucket, as shown in the following figure:
    The next step

    Tip

    Don't forget that you can always build and run your app for Android using Apportable.

The Cocos2d update loop

In our game, the update method was seen for the first time. This will most likely be used in every game, so it will now be covered in more detail.

There are two types of update methods:

  • update:(CCTime)delta: This update method has a dynamic time step. It is called directly before the frame is rendered. Cocos2d attempts to render your game at 60 frames per second.

    Note

    If your game consumes too much processing time, then the game's frame rate will decrease. The update method will then be called less-than 60 times per second.

    The delta parameter shows the time since the last update call in milliseconds.

  • fixedUpdate:(CCTime)delta: This update method is guaranteed to be called at a specified interval. It is recommended to use this when you require property changes on physics-based objects. The integrated physics engine operates on this update method.

These update methods are available inside every CCNode. The update method is called on each node by the CCDirector class...

Scenes

Scenes in Cocos2d are used extensively to break the game into manageable components. While it would be possible to create your entire game in one scene, it is certainly not advisable. The scene is the root node of your node hierarchy. Each scene is a subclass of the CCNode class. Only one scene can be active at any time, and changing the active scene is managed by the CCDirector class .

Scene life cycle

Cocos2d provides multiple events that are called at certain points in the life cycle of your scene. You can override these events in any CCNode subclass, and not just the CCScene class. The following events are available:

  • init: This method is called when a scene is initialized in code. If the scene was created in SpriteBuilder, this method is not called. This method is normally where you build your scene by adding child nodes.
  • didLoadFromCCB: This method is called when your scene is created in SpriteBuilder. It is called when the complete scene is loaded and all the code connections have...

Summary

You now have a basic knowledge of Cocos2d and have created your first game! You know about CCNode and the scene graph. You learned the common CCNode subclasses, including CCSprite for 2D images, CCButton for buttons, and CCLabelTTF for text. You also learned how to organize your game into different scenes using CCScene and, how to transition between these scenes using the CCDirector-shared instance. You also learned how to run code on every frame by using the update methods provided in CCNode.

In the next chapter, you will discover how you can avoid all the repetitive initialization code by using the graphical editor: SpriteBuilder.

Left arrow icon Right arrow icon

Description

If you are a game developer with experience in Objective-C and are interested in creating games for iOS or Android, this is the book for you. It will help you to quickly get started with Cocos2D and guide you through the process of creating a game, giving you the essential skills and knowledge you need to do so.

Who is this book for?

If you are a game developer with experience in Objective-C and are interested in creating games for iOS or Android, this is the book for you. It will help you to quickly get started with Cocos2D and guide you through the process of creating a game, giving you the essential skills and knowledge you need to do so.

What you will learn

  • Use sprites and nodes to create scenes to form the foundation of your game
  • Discover how SpriteBuilder and its graphical tools can be used to develop your game and increase its complexity
  • Design professional, impressive, and funfilled animations
  • Create an impressive user interface for an engaging gaming experience
  • Explore and use physics engines for attractive gameplay and use them to add a professional finish to your game
  • Add physics to your game for a more realistic experience
  • Accept user input through a variety of methods including touch and accelerometer

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 23, 2015
Length: 136 pages
Edition : 2nd
Language : English
ISBN-13 : 9781784391294
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 : Jan 23, 2015
Length: 136 pages
Edition : 2nd
Language : English
ISBN-13 : 9781784391294
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.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
AU$249.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 AU$5 each
Feature tick icon Exclusive print discounts
AU$349.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 AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 167.97
Learning Cocos2d-JS Game Development
AU$45.99
Cocos2d Game Development Blueprints
AU$75.99
Cocos2d Game Development Essentials
AU$45.99
Total AU$ 167.97 Stars icon
Banner background image

Table of Contents

7 Chapters
1. Getting Started with Cocos2d Chevron down icon Chevron up icon
2. Nodes, Sprites, and Scenes Chevron down icon Chevron up icon
3. SpriteBuilder Chevron down icon Chevron up icon
4. Animation with SpriteBuilder Chevron down icon Chevron up icon
5. User Interaction and Interface Chevron down icon Chevron up icon
6. Physics Engines Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(2 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
Cole Apr 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is perfect for those looking to get into Cocos2D game development on IOS and Android devices. Before going any further into this review, I would just like to point out first that instructions through out this textbook relies on the user working in a Mac OS environment.Personally, I had no experience with Cocos2D when I first delved into this textbook, and I lacked any Apple hardware to follow along with the tutorials contained with in. Although this was my case, I was still able to learn and follow along thanks to their images of what the game would look like after given code examples. I now feel more confident with the fact that I can work in an Apple environment, and development full games utilizing Cocos2D.Following each tutorial will not leave the reader in the dark with resources to use. In the beginning of the textbook, a link is provided to download images used as examples throughout the book. Perhaps you want to be more creative? A segment of the book will cover an application called "Sprite Builder" downloaded from the Apple App Store, and how easy it is to have it work with Cocos2D.This was a well put together textbook, with steps to help ease new users into using Cocos2D without being tossed into the deep end of Game Development. At no point did the book ever feel overwhelming. If you would like to start developing game for IOS and Android, I would certainly recommend the book to you.
Amazon Verified review Amazon
Christopher Haupt Apr 19, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Our Indie Studio builds its own projects as well as pays the bills with some consulting/for hire work. I’m a believer in in-expensive (time, cost) ways to test ideas, using rapid prototyping via paper or digitally. It is a big win if you can test a game idea, mechanic, technique, or interesting tool before getting too far committed on a project.So, while I'm not a beginner by any stretch, I had this prototyping mindset going while reading a review copy of "Cocos2D Game Development Essentials”. The book's subtitle is "Bring your mobile game ideas to life with Cocos2D”, and that got me thinking about "idea testing" using Cocos2D again. Recently I've been more Unity3D focused for prototyping, but interesting work in the Cocos2D universe has lead me to want to dive in again.This book is a VERY brief dive into Cocos2D and the new cool SpriteBuilder. I like that it walks you through some of the really core framework concepts of nodes, sprites, and scenes. Most of the book is devoted to using SpriteBuilder to quickly assemble a game. Note that the book uses Objective-C (not Swift, though you can find other good resources for Apple's language of the future). While iOS is the default target, the book does mention Android and Apportable (which makes sense, give the company's involvement with sponsoring the project).I'm happy with this book as a quick weekend "tutorial" to guide me mostly through getting a handle on what I might be able to do with SpriteBuilder. The book is definitely not a thorough and complete guide to the tools or the framework, so don't expect that. It may pique your interest enough to look elsewhere (I suggest tutorials from places like http://www.raywenderlich.com/).I'd give it 5 stars if it didn't end so abruptly. You get a taste of using physics (via Chipmonk) and then boom, you are done. No sound, networking, or general publishing. It feels cut off and I don't get a good set of pointers of what to read/do next.
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.