window.soundM = { sound : null } cc.Class({ extends: cc.Component, properties: { Sound_BGM: { default: null, type: cc.AudioClip }, StartGame_Clip: { default: null, type: cc.AudioClip }, Login_Clip: { default: null, type: cc.AudioClip }, StartToPlayTutorial_Clip:{ default: null, type: cc.AudioClip }, Tutorial_Clip:{ default: null, type: cc.AudioClip }, Settlement_Clip: { default: null, type: cc.AudioClip }, Close_Clip: { default: null, type: cc.AudioClip }, Score_Clip: { default: null, type: cc.AudioClip }, }, start () { this.playScoremin = 0; this.playScoreNum = 0; this.playScoreMax = 6; this.schedule(function(){ cc.sys.garbageCollect(); },10); soundM.sound = this; this.initBG(); cc.game.on(cc.game.EVENT_HIDE, function(){ console.log("游戏进入后台"); cc.audioEngine.setMusicVolume(0); },this); cc.game.on(cc.game.EVENT_SHOW, function(){ console.log("重新返回游戏"); cc.audioEngine.setMusicVolume(0.5); },this); }, initBG : function(){ cc.audioEngine.playMusic(this.Sound_BGM,true); cc.audioEngine.setMusicVolume(0.5); }, startToPlayTutorial: function () { this.StartToPlayTutorial_ClipID = cc.audioEngine.play(this.StartToPlayTutorial_Clip,false,1); return this.StartToPlayTutorial_ClipID; }, playTutorial: function () { this.Tutorial_ClipID = cc.audioEngine.play(this.Tutorial_Clip,false,1); return this.Tutorial_ClipID; }, playScore: function () { if (this.playScoreNum <= this.playScoreMax) { this.playScoreNum++; }else{ this.Score_ClipID = cc.audioEngine.play(this.Score_Clip,false,0.2); this.playScoreNum = this.playScoremin; } return this.Score_ClipID; }, playLogin : function () { this.Login_ClipID = cc.audioEngine.play(this.Login_Clip,false,1); return this.Login_ClipID; }, playStartGame : function () { this.StartGame_ClipID = cc.audioEngine.play(this.StartGame_Clip,false,1); return this.StartGame_ClipID; }, playSettlement : function () { this.Settlement_ClipID = cc.audioEngine.play(this.Settlement_Clip,false,1); return this.Settlement_ClipID; }, playClose : function () { this.Close_ClipID = cc.audioEngine.play(this.Close_Clip,false,1); return this.Close_ClipID; }, stopAll : function(){ // this.unschedule(this.findWorkCallback); cc.audioEngine.stopAll(); }, stopMusic : function(){ // this.unschedule(this.findWorkCallback); cc.audioEngine.stopMusic(); }, stop : function(ID){ // this.unschedule(this.findWorkCallback); cc.audioEngine.stop(ID); }, stopAllSoundEffect : function(){ cc.audioEngine.stop(this.StartToPlayTutorial_ClipID); cc.audioEngine.stop(this.Tutorial_ClipID); cc.audioEngine.stop(this.Login_ClipID); cc.audioEngine.stop(this.StartGame_ClipID); cc.audioEngine.stop(this.Settlement_ClipID); cc.audioEngine.stop(this.Close_ClipID); } });