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

Creating a sound menu


There are several ways to create a menu, and the most interesting is to create the graphic assets of every menu item, then add touch or mouse listeners, and handle the whole thing in a way you should already know.

This time, you'll see something new: the Cocos2d-JS built-in Menu class.

This is the content of gameScript.js:

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();
    this.audioEngine = cc.audioEngine;
    var playSoundMenu = new cc.MenuItemFont.create("Play Sound effect",this.playSound,this);
    playSoundMenu.setPosition(new cc.Point(0,350));
    var playBGMusicMenu = new cc.MenuItemFont.create("Play BG music",this.playBGMusic,this);
    playBGMusicMenu.setPosition(new cc.Point(0,300));
    var stopBGMusicMenu = new cc.MenuItemFont.create("Stop BG music",this.stopBGMusic,this)...