Book Details

About This Book

Create games from start to finish by writing code and following detailed step-by-step instructions

Full of illustrations and diagrams, practical examples, and tips for deeper understanding of game development in Cocos2D for iPhone

Who This Book Is For

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).

Table of Contents

Chapter 1: All About Cocos2D

Game engines

Why Cocos2D?

Games created with Cocos2D

Summary

Chapter 2: Hello Cocos2D

Starting with Xcode

Integrating Cocos2D with Xcode

Time for action – downloading and installing Cocos2D

Creating a Hello World project

Time for action – creating a new project from a template

Time for action – running the project on the simulator

Modifying the project

Time for action – creating a new scene

Time for action – displaying the world

Time for action – displaying the welcome label

Reviewing Cocos2D distribution

Time for action – running tests

Summary

Chapter 3: Cocos2D – Under the Hood

Reviewing Cocos2D

Summary

Chapter 4: Rendering Sprites

Creating the game project

Time for action – creating the Cocohunt Xcode project

Time for action – creating GameScene

Adding sprites to your game

Time for action – adding the background sprite

Time for action – adding the player character

Time for action – fixing z-order

Adding more sprites and moving them

Time for action – adding birds

Time for action – making the bird move

Understanding debug FPS labels

Spritesheets and animation

Time for action – creating a spritesheet

Time for action – modifying the game to use spritesheets

Time for action – animating the birds

Summary

Chapter 5: Starting the Action

Making the hunter aim and shoot

Time for action – handling touches

Time for action – aiming at the touch position

Time for action – shooting the arrow

Adding more birds to the GameScene class

Time for action – adding more birds

Time for action – detecting if the arrow hits the bird

Winning, losing, and other states

Time for action – using states for the bird's life cycle

Time for action – animating the shooting and limiting the shooting rate

Time for action – winning or losing the game

Improving the gameplay

Time for action – limiting the aiming range

Time for action – alternative control using a gyroscope

Summary

Chapter 6: Rendering Text

The easy way – CCLabelTTF

Time for action – adding labels

Time for action – updating labels

Using bitmap fonts for better performance

Time for action – creating a bitmap font using Glyph Designer

Time for action – adding hit points

Time for action – adding the win and lose labels

Summary

Chapter 7: Animations and Particle Systems

Using frame-based animation

Time for action – exploding coconut

Animating using actions

Time for action – hitting the bird animation

Skeletal animation

Creating particle systems for advanced effects

Time for action – adding the feathers explosion

Time for action – adding a fire to the scene

Time for action – using Particle Designer

Summary

Chapter 8: Adding Sound Effects and Music

Creating AudioManager and playing sound effects

Time for action – adding the AudioManager class

Time for action – finding and playing our first sound effect

Time for action – playing the remaining sound effects

Music and background sounds

Time for action – adding background sounds

Time for action – adding music

Enhancing Cocohunt sound effects

Time for action – preloading sound effects

Time for action – playing a sound at position

Summary

Chapter 9: User Interface and Navigation

Using buttons

Time for action – adding menu buttons

Time for action – toggling sound and music

Time for action – storing settings in NSUserDefaults

Navigating between scenes

Time for action – pushing AboutScene

Time for action – using more transitions

Time for action – using the scroll view to select levels

Creating modal dialogs and using text input

Time for action – pausing the game with a pause dialog

Time for action – restarting and exiting the game

Time for action – displaying stats when losing and winning

Entering and displaying highscores

Time for action – displaying highscores with CCTableView

Time for action – using the text field

Summary

Chapter 10: Physics

Creating a physics world

Time for action – creating a game level with physics

Time for action – adding ground to the scene

Time for action – adding the hunter

Time for action – fixing the hunter movement

Detecting and filtering collisions

Time for action – detecting and ignoring collisions

Time for action – filtering collisions using a collision mask

Time for action – filtering collisions using collision groups

Applying forces and impulses and using joints

Time for action – launching stones

Time for action – adding angry birds

Summary

Chapter 11: Working with Tile Maps

Creating tile maps

Time for action – creating a tileset

Time for action – creating a tile map

Time for action – creating the Retina version of the tile map

Using the tile maps

Time for action – creating TilemapScene

Time for action – moving and following the bird

Time for action – using parallax scrolling

Summary

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 In-App purchases

In Detail

Cocos2D-iPhone (Cocos2D-Swift) is a robust yet simple-touse 2D game framework for iPhone. If you are just starting with game programming, Cocos2D will enable you to make your first game in no time. Even if you are a seasoned game developer, you will still be able to benefit from what Cocos2D offers.

This book will set you on the fast-track to game development with Cocos2D for iPhone. You will start by reviewing the basic classes and hierarchy, dive deep into animations and game flow, and finish by creating a complete game with UI using some advanced techniques.

You will begin the book with an empty Cocos2D project and build on it until you end up with a complete game. The book will teach you how to work on game logic, handling user input, controlling the character, and playing audio. Later, in the final part of the book, we'll have a working game on our hands, and we'll see how we can improve the game further

Authors

Kirill Muzykov

Kirill Muzykov has been passionate about programming since the age of six, when he wrote his first line of code in BASIC. After graduating from university, he worked for a couple of years in a software development company, but then decided he wanted to be in charge and founded a new company with two of his colleagues.

It took several years to grow the company from a small team consisting of cofounders to one of the leading companies in the region. However, after almost six years and dozens of completed projects for clients, he tried game development and fell in love with it. A few years ago, he made a big turn in his career and started working as an independent game developer.

In his free time, he loves to play games and watch Simpsons and Futurama. You can find his blog and forum for this book at www.kirillmuzykov.com.

Table of Contents

Chapter 1: All About Cocos2D

Game engines

Why Cocos2D?

Games created with Cocos2D

Summary

Chapter 2: Hello Cocos2D

Starting with Xcode

Integrating Cocos2D with Xcode

Time for action – downloading and installing Cocos2D

Creating a Hello World project

Time for action – creating a new project from a template

Time for action – running the project on the simulator

Modifying the project

Time for action – creating a new scene

Time for action – displaying the world

Time for action – displaying the welcome label

Reviewing Cocos2D distribution

Time for action – running tests

Summary

Chapter 3: Cocos2D – Under the Hood

Reviewing Cocos2D

Summary

Chapter 4: Rendering Sprites

Creating the game project

Time for action – creating the Cocohunt Xcode project

Time for action – creating GameScene

Adding sprites to your game

Time for action – adding the background sprite

Time for action – adding the player character

Time for action – fixing z-order

Adding more sprites and moving them

Time for action – adding birds

Time for action – making the bird move

Understanding debug FPS labels

Spritesheets and animation

Time for action – creating a spritesheet

Time for action – modifying the game to use spritesheets

Time for action – animating the birds

Summary

Chapter 5: Starting the Action

Making the hunter aim and shoot

Time for action – handling touches

Time for action – aiming at the touch position

Time for action – shooting the arrow

Adding more birds to the GameScene class

Time for action – adding more birds

Time for action – detecting if the arrow hits the bird

Winning, losing, and other states

Time for action – using states for the bird's life cycle

Time for action – animating the shooting and limiting the shooting rate

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.