Cocos Creator 如何做到切换场景还能继续播放背景音乐?
目前的现状是,只要 loadScene 背景音乐就停止了。
采用的播放方式是:
使用 AudioSource 播放
1、创建一个空节点
2、在这个空节点上,添加一个 ‘其他组件’ - ‘AudioSource’
3、在脚本上预设好 AudioSource,并且根据实际需求,完善脚本的对外接口,如下:
cc.Class({
properties: {
audioSource: {
type: cc.AudioSource,
default: null
},
},
play: function () {
this.audioSource.play();
},
pause: function () {
this.audioSource.pause();
},
});