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)...