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 particles


Do you remember that in your assets folder, there's a yellow circle called particle.png? You will use it to create a nice particle effect to simulate the spaceship engine.

Discussing particle systems is beyond the scope of this book, so for more detailed information as well as complete particle generation software compatible with Cocos2d-JS, take a look at https://71squared.com/particledesigner.

Here, you are just going to add the simplest particle effect ever, but you will see it has a visual appeal like the following figure:

First, create a new global variable:

var background;
var gameLayer;var scrollSpeed = 1;
var ship;
var gameGravity = -0.05;
var gameThrust = 0.1;
var emitter;

The emitter will be created and configured in game's init function:

init:function () {
  this._super();
  this.setMouseEnabled(true);
  background = new ScrollingBG();
  this.addChild(background);
  this.scheduleUpdate();
  this.schedule(this.addAsteroid,0.5)
  ship = new Ship();
  this.addChild(ship...