Book Image

Cocos2d-X Game Development Blueprints

By : Karan Sequeira
Book Image

Cocos2d-X Game Development Blueprints

By: Karan Sequeira

Overview of this book

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

Preface

Cocos2d-x offers you, as a game developer, an open source engine that enables you to effortlessly build powerful 2D games and publish them on a multitude of popular platforms. In today's fast-paced world, what more could a game developer need?

This book gets you started by introducing the continually evolving HTML5 platform and familiarizes you with the Cocos2d-html5 framework.

This book is written to get you well versed with the many versatile features of Cocos2d-x, by demonstrating the creation of nine different games—from arcade style games to new age physics games and from simple puzzle games to strategic tower defense games! All the while, focusing on gameplay and letting Cocos2d-x do all the heavy lifting for you.

For the finale, you will learn how to build your games for Android and Windows Phone 8, bringing you to a full circle on Cocos2d-x.

What this book covers

Chapter 1, A Colorful Start, introduces the HTML5 version of the Cocos2d family by creating a simple and colorful puzzle game. You will learn how to set up your environment to develop using the Cocos2d-html5 engine. You also get familiar with the various actions you can use to get things done in an instant.

Chapter 2, How to Fly a Dragon!, concludes your HTML5 journey and will show you how to use sprite sheets, how to implement simple gravity, and use rectangular collision detection.

Chapter 3, Not Just a Space Game, shows you how to create a multiplatform Cocos2d-x project. You will also learn to create a level-based arcade game where you learn how to parse XML, play particle effects, and extend the engine by inheriting from its primary classes.

Chapter 4, Back to the Drawing Board, shows you just how easy it is to make a game that completely uses primitive drawing for its entities. You will also learn how to implement simple accelerometer controls and how to add difficulty progression to an endless game.

Chapter 5, Let's Get Physical!, guides you through the process of using Box2D to build a physics game. You will also learn about state machines and object pools.

Chapter 6, Creativity with Textures, shows you how to fire OpenGL commands and render your own sprite. You will also learn to use Box2D to make a picturesque side-scroller game.

Chapter 7, Old is Gold!, introduces you to the Tiled map editor and the basics of a tile-based game. You will also learn how to implement a reusable tile-based collision detection algorithm.

Chapter 8, Box2D Meets RUBE, introduces you to RUBE, which is a powerful physics editor. You will use it to create levels for a slingshot type physics game. You will also learn about ray casting and how to implement explosions in Box2D.

Chapter 9, The Two Towers, shows you how easy it is to implement a tower defense game in Cocos2d-x. In the process, you will learn how to implement scalable architectures for your enemies and towers. You will also learn how a simple gesture recognizer works and how you can control the speed of your gameplay.

Chapter 10, Cross-platform Building, shows you how to set up your environment and build one of your games on Android and Windows Phone 8.

What you need for this book

The source bundle will contain all the source code and project files to run each game. However, you will need to install the following software to run the games:

  • A computer running Windows, Linux, or Mac OS. However, you will need a computer running Windows 8 in order to build on Windows Phone 8.

  • WebStorm, or a similar JavaScript editor, and at least one browser to run the HTML5 games in the first two chapters.

  • Microsoft Visual Studio to run the projects on Windows PC and Windows Phone and Eclipse to run the projects on Android.

Who this book is for

This book is written for people who have basic experience in Cocos2d-x and want to use it to implement a wide variety of high-quality games. The book revisits some of the basic concepts, but we hit the ground running. As such, some basic understanding of Cocos2d-x is recommended. In addition, since the first couple of chapters are on Cocos2d-html5, some knowledge of JavaScript is strongly recommended.

Conventions

In this book, you will find a number of text styles 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: " If you expand the Classes folder inside pumpkindefenseComponent, you will notice that the actual sources are missing."

A block of code is set as follows:

createTileData:function(){
  this.tileData = [];
  // generate tile data randomly
  for(var i = 0; i < (NUM_COLS * NUM_ROWS); ++i){
    this.tileData[i] = 1 + Math.floor(Math.random() * MAX_COLOURS);
  }
}

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

export NDK_ROOT=/Android/android-ndk-r10

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: " By default, you will see a whole lot of packages selected, out of which Android SDK Platform-tools and Android SDK Build-tools are necessary."

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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in 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 at 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 from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/5265OS_ColorImages.pdf.

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 could 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.