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

Adding the Box2D engine to your project


The best game to write for you to learn most Box2D concepts is Totem Destroyer. It can be found at http://armorgames.com/play/1871/totem-destroyer.

You have to smash bricks by clicking/tapping on them while being careful not to let the totem fall to the ground, or it's game over. Not all bricks can be destroyed. In the level shown in the following screenshot, dark bricks can't be destroyed:

Although the game has quite a simple gameplay, it features some advanced physics concepts, such as collision detection and how to select a physics body.

We will build this level; so, as usual, the first thing we need to do is take care of the content of the assets folder:

And this is the content of loadassets.js:

var gameResources = [
  "assets/brick1x1.png",
  "assets/brick2x1.png",
  "assets/brick3x1.png",
  "assets/brick4x1.png",
  "assets/brick4x2.png",
  "assets/ground.png",
  "assets/totem.png"
];

To keep loading times as fast as possible, the basic Cocos2d-JS source...