使用audioEngine播放背景音乐,在android手机切换场景, 新场景没有添加背景音乐,但有时候会播放上一个场景的背景音乐,不知道什么问题,打印信息看根本没有调用播放,在新的场景里边就会播放
cc.Class({
extends: cc.Component,
properties: {
audio: {
url: cc.AudioClip,
default: null
}
},
onLoad: function () {
this._current = null;
if(tydf.musicBackgroundState){
this._current = cc.audioEngine.play(this.audio, true, tydf.musicBackgroundState);
}
},
refreshBackGroundMusicState:function(){
if(this._current !== null){
if(tydf.musicBackgroundState){
cc.audioEngine.resume(this._current);
}
else{
cc.audioEngine.pause(this._current);
}
}
else if(tydf.musicBackgroundState){
this._current = cc.audioEngine.play(this.audio, true, tydf.musicBackgroundState);
}
},
onDestroy: function () {
if(this._current !== null){
cc.audioEngine.stop(this._current);
}
cc.audioEngine.uncache(this.audio);
this.audio = null;
}
});
