Book Image

Learning Cocos2d-JS Game Development

By : Emanuele Feronato
Book Image

Learning Cocos2d-JS Game Development

By: Emanuele Feronato

Overview of this book

Table of Contents (18 chapters)
Learning Cocos2d-JS Game Development
Credits
Foreword
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Creating Your Own Blockbuster Game – A Complete Match 3 Game
Index

Preface

Mobile HTML5 casual games are experiencing a golden age these days. Not only famous Flash hits and successful native mobile games, but also original games tailored for mobile browsers are played by millions of players everyday.

With a continuously growing number of mobile devices available to play HTML5 games, and with each one having its own resolution, and display size, and ratio, creating a game version for each device would make you waste a lot of time. That's why there's a new way to make HTML5 games called cross-platform. It means you create a game once, and some magic adapts it to every device capable of running HTML5 content.

This magic is called Cocos2d-JS, which allows you to focus on what you actually love, making games, and takes care of screen resolutions and ratios. Also, you will be using one of the simplest and most widely known languages ever: JavaScript. Last but not least, it's free. You can create the next big game at no cost.

Throughout this book, you will learn how to make games using Cocos2d-JS in the most fun and productive way. We know you hate boring theories, so we did our best to focus the entire book on one single word: action.

Learn Cocos2d-JS with examples taken from the most successful game genres; see how easy it is to create a game once, and then make it run on each device.

What this book covers

Chapter 1, Hello World – A Cross-platform Game, will show you how to create a blueprint that you will be using for every game you will make with Cocos2d-JS. This chapter will also guide you through the creation of an environment to create and test your cross-platform games.

Chapter 2, Adding Interactivity – The Making of a Concentration Game, guides you through the creation of one of the most popular games that makes you learn how to create sprites and interact with them both with the mouse and finger.

Chapter 3, Moving Sprites Around the Screen – An Endless Runner, introduces scrolling and sprite movements using motion tweens in the creation of a space-themed endless runner. Particle effects and collision detection complete the game experience.

Chapter 4, Learn about Swipes through the making of Sokoban, shows you how to create a classic puzzle game that you can control with the most intuitive way used these days: swiping on the game.

Chapter 5, Become a Musical Maestro, examines the importance of having sound effects and background music in your games. This chapter also shows you how to start and stop sounds and loops by adjusting their volume.

Chapter 6, Controlling the Game with Virtual Pads, provides you three different ways to control your games with virtual pads when you build a fruit game. Virtual buttons and analogic pads will be your best friends when you create your next game.

Chapter 7, Adding Physics to Your Games Using the Box2D Engine, shows you the magic of physics engines in the creation of the blockbuster Totem Destroyer game, which you will easily build using the Box2D physics engine. You will also learn how to create, destroy, skin, and interact with physics bodies in a realistic physics environment.

Chapter 8, Adding Physics to Your Games Using the Chipmunk2D Engine, creates the same Totem Destroyer game, this time using Chipmunk2D rather than Box2D. While the Web is divided by the Box2D versus Chipmunk2D war, you will learn both of them, leaving the choice of your favorite physics engine up to you.

Chapter 9, Creating Your Own Blockbuster Game – A Complete Match 3 Game, completes the book with the creation of the most successful game genre today: a Match-3 game. At the end of the chapter, you will also find some hints and suggestions on protecting, promoting, marketing, and monetizing your game.

What you need for this book

Cocos2d-JS is so easy to use, apart being free; it basically does not require anything but a text editor and a server to run your projects. If you want, you can use the Cocos2d-JS official IDE, but you're welcome to use your favorite text editor if you prefer.

Who this book is for

Whether you are an experienced game developer coming from another language or a complete novice, this book can guide you through the creation of cross-platform games. Some basic knowledge of JavaScript is recommended, then just follow book examples.

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: "I found myself almost rewriting the game with a series of if.. then.. else trying to make it look good on any device."

A block of code is set as follows:

var gameScene = cc.Scene.extend({
  onEnter:function () {
    this._super();
    gameLayer = new game();
    gameLayer.init();
    this.addChild(gameLayer);
  }
});

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

var gameScene = cc.Scene.extend({
  onEnter:function () {
    this._super();
    gameLayer = new game();
    gameLayer.init();
    this.addChild(gameLayer);
  }
});

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: "If you now open the developer console, you should see: my awesome game starts here".

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.

Downloading the color images of this book

We also provide you with a PDF fie 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 fie from: https://www.packtpub.com/sites/default/files/downloads/0075OS_ColoredImages.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 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.