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 asteroids


As the spaceship flies from left to right (actually it does not, but that's how it seems), you have to add asteroids, which enter the screen from the right-hand side of the game.

Now, you can just place some asteroid sprites on the right-hand side of the screen and make them move to the left-hand side just like you did with the background cityscape, but you wouldn't learn anything new if you did that, so let's see another way to manage sprite movement.

First things first, before you can move an asteroid, you have to create it.

In this game, a new asteroid will appear every half a second, so it's time to schedule another event in the game class declaration:

var game = cc.Layer.extend({
  init:function () {
    this._super();
    cc.eventManager.addListener({
      event: cc.EventListener.MOUSE,
      onMouseDown: function(event){
        ship.engineOn = true;
      },
      onMouseUp: function(event){
        ship.engineOn = false;
      }
    },this)
    background = new ScrollingBG...