//**************** 常驻节点 + cc.audioEngine的方式播放背景音乐是最有效果的 *****************//
onLoad() {
cc.anudiocontrol = this;
cc.game.addPersistRootNode(this.node);
console.log('AudioSourceControl onLoad ');
cc.anudiocontrol.playAudio();
cc.audioEngine.play(this.audioClipBg,true,1)
cc.anudiocontrol.playBgMusic()
},
playBgMusic() {
cc.loader.loadRes(“Audio/sound_bg.mp3”, (err, sound) => {
if (!err) {
if(this.BgMusic){
cc.audioEngine.stopAll();
this.BgMusic = cc.audioEngine.play(sound,true,1);
console.log(“背景音乐存在,直接播放”);
}else{
this.BgMusic = cc.audioEngine.play(sound,true,1);
console.log("背景音乐 不存在,播放加loadRes的音乐");
}
}
});
},
stopBgMusic() {
if(this.BgMusic){
cc.audioEngine.stop(this.BgMusic);
console.log("停止背景音乐");