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
€8.99 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Cyprus

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

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 : 9781784390327
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Cyprus

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Publication date : Jan 23, 2015
Length: 136 pages
Edition : 2nd
Language : English
ISBN-13 : 9781784390327
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 91.97
Learning Cocos2d-JS Game Development
€24.99
Cocos2d Game Development Blueprints
€41.99
Cocos2d Game Development Essentials
€24.99
Total 91.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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela