cocosCreator 控制音乐,音效的图片转换

这篇博客介绍了在cocosCreator中如何有效地控制背景音乐和音效。通过常驻节点和cc.audioEngine,实现背景音乐的循环播放。同时,展示了如何使用cc.AudioEngine或cc.audioSource播放音效,并提供了声音开关的功能,包括点击事件处理和状态存储。
摘要由CSDN通过智能技术生成

//**************** 常驻节点 + 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("停止背景音乐");
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值