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
Cocos2d Game Development Blueprints
Cocos2d Game Development Blueprints

Cocos2d Game Development Blueprints: Design, develop, and create your own successful iOS games using the Cocos2d game engine

Arrow left icon
Profile Icon Jorge Jordán
Arrow right icon
₱579.99 ₱2245.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (2 Ratings)
eBook Jan 2015 440 pages 1st Edition
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial
Arrow left icon
Profile Icon Jorge Jordán
Arrow right icon
₱579.99 ₱2245.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (2 Ratings)
eBook Jan 2015 440 pages 1st Edition
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial

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 Blueprints

Chapter 2. Explosions and UFOs

One of the most interesting characteristics in iOS devices is the accelerometer, thanks to which you can, among other functionalities, control the movement of the main character of a game without needing to touch the screen. In this chapter, you will learn how to take advantage of this feature and mix it with particles such as explosions and fire to develop a classic shoot 'em up game like 1942, but in this case, the enemies will be UFOs. As you will need some spaceships, you will learn how to create them by extending the CCSprite class and I will also teach you how to implement the parallax effect to create an illusion of depth in a 2D game. To conclude, I will introduce you to geometric primitives such as lines, squares, and circles and how to draw them.

Things you will learn in this chapter include:

  • How to use the accelerometer
  • How to load and set up a particle system
  • How to create sprites that extend CCSprite
  • How to implement the parallax effect...

Handling the accelerometer input

Since the apparition of the first iPhone generation, mobile devices are equipped with a 3-axis accelerometer (x, y, and z) to detect orientation changes and it has modified the course of handheld games. It allows players to interact with games without the need to touch the screen, and it allows developers to create new subgenres of games too.

Throughout this chapter, you will mix this hardware feature with a classic arcades genre to develop the following game: the planet Earth has been attacked by an army of UFOs whose sole purpose is to wipe out all of mankind, but fortunately, a mad scientist equipped with some of his inventions is brave enough to defend us.

To control the movements of Dr. Nicholas Fringe, our mad scientist, you will take advantage of the accelerometer, but first of all you need a clean Xcode project. As you learned in the previous chapter how to create a new project and how to get it ready to start developing, we will skip this step, so...

Implementing the parallax effect in Cocos2d

The parallax effect is a scrolling technique used in 2D games that simulates depth and displacement by moving the foreground layers faster than background layers. This technique was developed initially to be used in traditional animation in the 1930s and was first used in computer games in the early 80s.

This effect consists of making our brain think that we are looking at displacement similar to what happens when we are traveling on a train: we can see the trees near the railway passing fast, but if we look to the houses placed further away, they pass a little slower, and if you look at the mountains in the background, they look almost immobile. If we place our scientist over a ground layer that will displace slowly and above this layer we scroll a clouds layer from the top to the bottom of the screen, our brain will think that Dr. Fringe is flying over the clouds thanks to his amazing backpack-reactor.

CCParallaxNode

As the parallax effect is a...

Particle systems

I always say that video games are comparable to films, differences aside, because they tell stories, have an argument, different scenes, a soundtrack, and special effects. Yes, you read correctly, you can add special effects, or particle systems as they're commonly known in computer games, to your games.

In computer graphics, this technique is commonly used because it simulates several natural and meteorological phenomena such as snow, sun, rain, fire, meteors, and smoke. It also simulates other special effects such as spirals, explosions, fireworks, and other lighting effects by using a large amount of small images. If you think about natural phenomena, like rain for example, it is composed of hundreds of water droplets and so that's what we need to replicate if we want to simulate a particle system in Cocos2d.

You might be thinking that this task must be hard and offers little possibilities, but in this section, you will learn to create and customize your own...

Extending CCSprite

Dr. Nicholas Fringe's enemies are an army of UFOs controlled by very intelligent extraterrestrial beings trying to wipe out all of mankind. That's why we're going to create them as a separate class that will derive from CCSprite, where we will define its evolved behavior.

Some developers prefer to derive this kind of class from CCNode and include a CCSprite instance as it offers more potential, but for the moment we are going to keep it simple and just extend CCSprite.

First of all, let's create the new class:

  1. Right-click on the Classes group in the project navigator and select New File….
  2. Click on iOS | cocos2d v3.x and choose to create the new file from the CCNode class template.
  3. Type CCSprite in the available field and click on Next.
  4. Call the file as UFO and be sure that the Classes folder is selected before clicking on Create.

Then replace the contents of UFO.h with the following block of code:

#import <Foundation/Foundation.h>
#import &quot...

2-star challenge – create explosions

Now that we are able to detect when a UFO is destroyed, it would be more realistic to make them explode, and I think you're ready to develop this by yourself.

Create one explosion whenever a spaceship is destroyed by using the file explosion.png that you will find in the Resources folder.

The solution

You will need to go back a few pages to achieve this challenge because in this case, we're going to create a CCParticleSystemModeRadius particle.

First of all, add explosion.png to the project and then add the following lines inside the method detectCollisions, after [_ufosToRemove addObject:ufo];:

CCParticleExplosion *explosion = [CCParticleExplosion node];
    explosion.texture = [CCTexture textureWithFile:@"explosion.png"];
         explosion.emitterMode = CCParticleSystemModeRadius;
         explosion.startSize = 100.0;
         explosion.startRadius = 20.0;
         explosion.endSize = 1.0;
         explosion.endRadius = 100.0...

Drawing and coloring

Usually, you will be working with sprites, nodes, and other high-level objects, but maybe sometimes you will want to draw some geometric primitives such as lines, circles, or squares. In our case, we're going to use them to represent our scientist's life bar.

Fortunately, Cocos2d allows us to perform these tasks easily by using any of these three options:

  • The draw method: This CCNode class method is the one you should override in your classes derived from CCNode to customize drawing your nodes. It's important here not to call [super draw] or you will face unexpected behavior.
  • The visit method: This CCNode class method gives you more control as it calls the draw method of the node and its children in the order they were added to it, taking into account the specified z-orders.
  • CCDrawNode: This class, derived from CCNode, is the one that gives you full control over the primitives because they are treated as nodes themselves.

The draw method presents a problem...

Handling the accelerometer input


Since the apparition of the first iPhone generation, mobile devices are equipped with a 3-axis accelerometer (x, y, and z) to detect orientation changes and it has modified the course of handheld games. It allows players to interact with games without the need to touch the screen, and it allows developers to create new subgenres of games too.

Throughout this chapter, you will mix this hardware feature with a classic arcades genre to develop the following game: the planet Earth has been attacked by an army of UFOs whose sole purpose is to wipe out all of mankind, but fortunately, a mad scientist equipped with some of his inventions is brave enough to defend us.

To control the movements of Dr. Nicholas Fringe, our mad scientist, you will take advantage of the accelerometer, but first of all you need a clean Xcode project. As you learned in the previous chapter how to create a new project and how to get it ready to start developing, we will skip this step, so...

Implementing the parallax effect in Cocos2d


The parallax effect is a scrolling technique used in 2D games that simulates depth and displacement by moving the foreground layers faster than background layers. This technique was developed initially to be used in traditional animation in the 1930s and was first used in computer games in the early 80s.

This effect consists of making our brain think that we are looking at displacement similar to what happens when we are traveling on a train: we can see the trees near the railway passing fast, but if we look to the houses placed further away, they pass a little slower, and if you look at the mountains in the background, they look almost immobile. If we place our scientist over a ground layer that will displace slowly and above this layer we scroll a clouds layer from the top to the bottom of the screen, our brain will think that Dr. Fringe is flying over the clouds thanks to his amazing backpack-reactor.

CCParallaxNode

As the parallax effect is a...

Left arrow icon Right arrow icon

Description

Whether you are a passionate gamer, like developing, or are just curious about game development, this book is for you. The book has been written to teach 2D game development to app developers and to teach Objective-C to game developers, as learning Cocos2d is the perfect step for both roles.

Who is this book for?

Whether you are a passionate gamer, like developing, or are just curious about game development, this book is for you. The book has been written to teach 2D game development to app developers and to teach Objective-C to game developers, as learning Cocos2d is the perfect step for both roles.

What you will learn

  • Load and control sprites, labels, sounds, and geometrical primitives efficiently to build the core of a game
  • Simulate movement by implementing the parallax effect and running animations
  • Implement turnbased game logic including Game Center
  • Create both iPadonly and universal versions of your games
  • Control your game using touches, an accelerometer, or a virtual game pad
  • Build menus and tutorials and define some artificial intelligence to nonplayed characters

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 30, 2015
Length: 440 pages
Edition : 1st
Language : English
ISBN-13 : 9781783987894
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 30, 2015
Length: 440 pages
Edition : 1st
Language : English
ISBN-13 : 9781783987894
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 ₱260 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 ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 6,736.97
Cocos2d Game Development Essentials
₱1683.99
Learning iPhone Game Development with Cocos2D 3.0
₱2245.99
Cocos2d Game Development Blueprints
₱2806.99
Total 6,736.97 Stars icon
Banner background image

Table of Contents

9 Chapters
1. Sprites, Sounds, and Collisions Chevron down icon Chevron up icon
2. Explosions and UFOs Chevron down icon Chevron up icon
3. Your First Online Game Chevron down icon Chevron up icon
4. Beat All Your Enemies Up Chevron down icon Chevron up icon
5. Scenes at the Highest Level Chevron down icon Chevron up icon
6. Physics Behavior Chevron down icon Chevron up icon
7. Jump and Run Chevron down icon Chevron up icon
8. Defend the Tower 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 Full star icon 5
(2 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
John Preston Cua Mar 22, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is the best Cocos2d Book I’ve worked through so far…This book (Cocos2d Game Development Blueprints) guides the reader in developing 7 different types of games:1.) Chapter 2’s “Explosions and UFOs” - A Game that uses accelerometer inputs to manipulate the movement of the player in the game. In this chapter the reader not only learns how to use the accelerometer of the device in one’s game for the actual left right movement of the player but also how to use the technique of parallax scrolling to give the ILLUSION of forward movement of the player. Other important learning points in this chapter are: a.) How to use Particle Systems for Explosion Animation b.) How to use draw Primitive Shapes2.) Chapter 3’s Online Game - The best part of this chapter for me is the working sample code provided that illustrates how to develop a turn-based card game. After working through this chapter you will most likely have a good or at least better idea on how to implement a turn-based online game using Apple’s Game Center. As a side note, most of the Cocos2d books I’ve worked through does not have a chapter on Game Centre and how to develop a turn-based game. So this is one of the more special points of this book.3.) Chapter 4’s “Beat all Your Enemies Up” Game - If you are like me, who has spent a good amount of your childhood time playing BEAT’EM UP games like DOUBLE DRAGON and GOLDEN AXE during the late 80s and early 90s, you may be very glad to know that after working through this chapter you will have the foundation and a STARTING TEMPLATE to work on to create your own BEAT’EM UP GAME. YEHEY!!4.) Chapter 5’s Math Game - This chapter’s GAME TEMPLATE and sample code is very suitable for educational game apps and for creating the SETTINGS screen of any game…very useful but didn’t get5.) Chapter 6’s Snooker Game - This chapter is all about using the CHIPMUNK PHYSICS ENGINE. The sample game in this chapter is a SNOOKER GAME and NOT ANGRY BIRDS…and so don’t expect to get a ANGRY BIRDS GAME TEMPLATE/BLUEPRINT from this chapter, but EXPECT TO LEARN HOW TO USE THE CHIPMUNK PHYSICS ENGINE in your game.6.) Chapter 7’s Jump and Run - This chapter is for all of the MARIO BROTHERS fans that are now Game Developer Aspirants as this chapter shows how to develop a PLATFORM Game like Mario Brothers.7.) Chapter 8’s Defend the Tower - This chapter discusses the development of a Tower Defence Game. For me the most special part of this chapter is its discussion on how to implement the path finding algorithm for the attackers. In other words, this chapter teaches the reader how to make the objects in one’s game move within the game through following a predefined path that you set. This one special knowledge contained in this chapter is something I appreciate a lot as I have not found this knowledge in any of the other Cocos2d books I’ve read except for one that is already totally outdated.In short, I highly recommend this book to anyone who would like to learn to use Cocos2d to create 2D games as this book attempts to give the reader the knowledge on how to create 7 different types of games and it does a fairly good job at that. Also, there are 2 things that set this book apart from most other Cocos2d books (Note: Read my point 2 and 7 above to find out what these are).As of writing this review (March 22, 2015), the contents of this book is still relevant to the current version of Cocos2d-Swift. If you are reading this book quite a while later than March 22, 2015, please ensure that the book’s Cocos2d’s MAJOR version is still applicable to the Cocos2d version you will be using otherwise you may just end up buying a book that is not the most suitable for the tool you will be using. I don’t think booksellers offer a refund for mistakenly buying a outdated book as well.…Below is a copy and paste from the book for people who want to make sure:“In this book, we work with the latest Xcode version (5.1.1 at the time of writing), Cocos2d v3.0.0, and iOS7. “It is also worth noting that the book came out Jan 30 2015.
Amazon Verified review Amazon
Roger Pingleton May 11, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Cocos2D is always evolving, so books tend to go out of date pretty quickly. Never the less, this is a great resource.
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.