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 Chipmunk2D engine to your project


As we will create the same game as the one in the previous chapter, I suggest you copy your project into a new folder since we will reuse most of the code already written in the previous chapter. All graphic assets will not change, so simply don't touch the assets folder. The same thing goes for the loadassets.js, main.js and project.json files.

So basically, the only file we will change is gamescript.js. Get ready to dive into the Chipmunk2D world.

A physics game, without physics

As we already built the Totem Destroyer game prototype, we can strip all the physics parts out of it and leave just the bare bones, where we will build the new physics engine.

The physics-stripped version of gamescript.js is:

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

var game = cc.Layer.extend({
  init:function () {
    this._super();
    var backgroundLayer...