加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-x之3.8音频管理

发布时间:2020-12-14 16:38:06 所属栏目:百科 来源:网络整理
导读:新版本引擎添加了音频预加载功能,jsb绑定了新的AudioEngine音频引擎,实测好用 /** * Created by Jerry on 15-8-25. */var GameAudio = GameAudio || { isOpenMusic : true,isOpenEffect : true,playMusic:function(filePath,isLoop){ if(!this.isOpenMusic

新版本引擎添加了音频预加载功能,jsb绑定了新的AudioEngine音频引擎,实测好用


/**
 * Created by Jerry on 15-8-25.
 */

var GameAudio = GameAudio || {
    isOpenMusic : true,isOpenEffect : true,playMusic:function(filePath,isLoop){
        if(!this.isOpenMusic) return;
        jsb.AudioEngine.play2d(this.getAllPath(filePath),isLoop,1.0,jsb.AudioEngine.getDefaultProfile());
    },stopMusic:function(filePath){
        jsb.AudioEngine.uncache(this.getAllPath(filePath));
    },playEffect:function(filePath){
        if(!this.isOpenEffect) return;
        jsb.AudioEngine.play2d(this.getAllPath(filePath),false,stopEffect:function(filePath){
        jsb.AudioEngine.uncache(this.getAllPath(filePath));
    },stopAll:function(){
        jsb.AudioEngine.stopAll();
    },getAllPath:function(filePath){
        var path = "";
        if(cc.sys.os == "android"){
            path = filePath + ".ogg";
        }else{
            path = filePath + ".mp3";
        }
        return path;
    },getAudioEngine:function(){
        return cc.audioEngine;
    },preloadSound:function(){
        for (var i in res_sound){
            if(cc.sys.os == "android"){
                jsb.AudioEngine.preload(res_sound[i] + ".ogg",null);
            }else{
                jsb.AudioEngine.preload(res_sound[i] + ".mp3",null);
            }
        }
    }
};
PS:stopAll()在切场景更换背景音乐时使用,先停,再播。。。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读