cocos2d-x之3.8音频管理

前端之家收集整理的这篇文章主要介绍了cocos2d-x之3.8音频管理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

新版本引擎添加了音频预加载功能,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()在切场景更换背景音乐时使用,先停,再播。。。 原文链接:https://www.f2er.com/cocos2dx/341097.html

猜你在找的Cocos2d-x相关文章