Book Image

Learning Cocos2d-x Game Development

By : Siddharth Shekar
Book Image

Learning Cocos2d-x Game Development

By: Siddharth Shekar

Overview of this book

Table of Contents (19 chapters)
Learning Cocos2d-x Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

GamesIndustry International (http://www.gamesindustry.biz/articles/2014-01-14-mobile-gaming-to-push-industry-above-USD100-billion-by-2017) states that by 2017, the global gaming business will be worth more than $100 billion. Out of this, the mobile and online gaming business with a compounded annual growth rate of 23.6 percent will be generating $60 billion.

The mobile phone as a gaming device, although new, is rapidly growing. Every day, there are new independent developers and small start-ups creating amazing games. They almost simultaneously release their games at different stores supporting different platforms to increase revenue.

Creating cross-platform games used to be a tedious task before. You had to code in different languages that were native to that device's OS, which could take a month for each platform. With Cocos2d-x, cross-platform game development is more accessible, as it is free and completely open source. With the same C++ code and resources, you can code once and deploy on different devices, such as Android, BlackBerry, iOS, Mac, Linux, Tizen, Win32, WinRT, and Windows Phone.

This book will show you how to create a cross-platform game from the ground up on a Windows machine for a Windows Phone. Apart from how to develop a game, the book will also cover how to publish the game on the Windows Phone Store and port the same game to different platforms, showcasing the true power of Cocos2d-x.

What this book covers

Chapter 1, Getting Started, is an introduction to Cocos2d-x with instructions to download and install Visual Studio 2012. It also shows you how to download Cocos2d-x and create a multiplatform project. This chapter guides you through the procedure to open the project in Visual Studio and run it on the Windows desktop, Windows Phone 8 simulator, and iOS device simulator.

Chapter 2, Displaying the Hero and Controls, shows you how to display the player and make it move around with various control mechanisms, such as actions, accelerometer, touches, and on-screen buttons.

Chapter 3, Enemies and Controls, shows you how to create a custom enemy class and a bullet class, make the enemy spawn from the right-hand side of the screen at different heights, and make the enemy move towards the left. The player has to tap on the left-hand side of the screen to make the hero reach the same height as the enemy and tap on the right-hand side of the screen to shoot.

Chapter 4, Collision Detection and Scoring, shows the different mechanics of collision detection and discusses their advantages and disadvantages. We will also see how to keep a track of our score.

Chapter 5, HUD, Parallax Background, and the Pause Button, shows you how to add a GUI and a scrolling background layer. It also explains the process of adding a pause and resume button along with a pause screen.

Chapter 6, Animations, discusses a couple of animation tools and techniques. Questions such as "What is a spritesheet animation?" and "How is it different from a skeletal animation?" will be answered. Also, it will show you how to animate characters using these techniques and how to change the state of the animation using state machines.

Chapter 7, Particle Systems, discusses how to include particles in the game. You will be taking a look at inbuilt particle systems in Cocos2d-x and creating your own custom particle system. You'll also get a glimpse of Particle Designer and other tools used to create particles.

Chapter 8, Adding Main and Option Menu Scenes, discusses Options and Play scenes, creating the main menu and credits scene, and adding GUI buttons on each of the screens to navigate between them. It also explains the process of loading the main screen once the game is loaded.

Chapter 9, Adding Sounds and Effects, shows you how to add the background score and sound effects in the game. It also discusses actions such as pausing and resuming sounds and effects and adding a mute button in the Options scene. You can also take a look at different audio formats and how to convert between them using the free software, Audacity.

Chapter 10, Publishing to the Windows Phone Store, lets you take a look at the Windows Phone Store. It explains the various steps needed to create a store account, prepare the app for upload, check the app on the local machine, and publish games on the Windows Phone Store.

Chapter 11, Porting, References, and Final Remarks, explains how to port the game on to different platforms, such as iOS and Android, using the same code base. It also lets you take a look at some of the useful website references, books, and blogs to take your coding and game development skills to the next level.

What you need for this book

Cocos2d-x can be run on any Mac, Windows, or Linux machine. Although this book only shows you how to run projects in Windows and Mac, the same concept can be used for developing on Linux. Although there are simulators to test the code on any platform, it is advisable to test and build on a device, so a Windows phone/tablet, Android phone/tablet, iPhone, or iPad is recommended.

Who this book is for

If you are a hobbyist, novice game developer, or programmer who wants to learn about developing games/apps using Cocos2d-x, this book is for you. To follow this book, you will need a good understanding of C++. This book is for you if you are curious about how games are made for handheld devices; if you want to learn the various tools that are used by industry professionals to speed up the game development process; and if you ever wanted to know how to create a store account, upload your app, and publish it on the Windows Phone Store.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The CCScene class can be used as a container of CCLayers."

A block of code is set as follows:

CCScene* HelloWorld::scene()
{
   CCScene *scene = CCScene::create();
    
   HelloWorld *layer = HelloWorld::create();
   
   scene->addChild(layer);
   
   return scene;
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    Enemy* e = Enemy::createEnemy(gameplayLayer);
    gameplayLayer->addChild(e);
    e->shoot(0.016);

Any command-line input or output is written as follows:

cd desktop\coco2d-x-2.2.3\tools\project-creator

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Click on Download and select VS2012_WDX_ENU.iso. Click on Next and the download should begin."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.