您当前位置: 首页 > Cocos > 精品代码 > Cocos Creator 背景音乐音效播放模块
Cocos Creator 背景音乐音效播放模块
收藏 报错 好评2

Cocos Creator 背景音乐音效播放模块

10.00 金币

源码类型:精品代码

上传日期:2018-03-27 00:05:05

源码编号:1621

高速下载源码

浏览:530 收藏:1 下载:1

详细介绍

调用方法 放在目录里面

cc.SY = this.addComponent("shengying");

即可 也可以直接绑定在 Canvas 上面

核心代码如下

cc.Class({
    extends: cc.Component,

    properties: {

        audioSource: {
            type: cc.AudioSource,
            default: []
        },nanaudio:{
            url: cc.AudioClip,
            default: []
        },nvaudio:{
            url: cc.AudioClip,
            default: []
        }
       
    },

    onLoad: function () {
        this._YingLiang = 1;
        this._YingXiao = 1;
        cc.SY = this;
        var YingLiang = parseFloat( cc.sys.localStorage.getItem('yingyue'));
        var YingXiao  =  parseFloat(  cc.sys.localStorage.getItem('yingxiao'));

        if(cc.sys.localStorage.getItem('yingxiao') == null){

            YingXiao = 1;
        }

        if(cc.sys.localStorage.getItem('yingyue') == null){
        
            YingLiang = 1;
        }

        this._YingLiang = YingLiang;
        this._YingXiao = YingXiao;

    },zyconfig(data){

        if(data.audioSource){

            this.audioSource = [];
            for(var i = 0; i < data.audioSource.length ; i++){ var shuju = cc.find(data.audioSource[i]); if(shuju){ var ziyuan = shuju.getComponent(cc.AudioSource); if(ziyuan){ this.audioSource.push( ziyuan ); } } } } if(data.nanaudio){ this.nanaudio = []; for(var i = 0; i < data.nanaudio.length ; i++){ this.nanaudio.push( cc.url.raw("resources/"+data.nanaudio[i]+".mp3" )); } } if(data.nvaudio){ this.nvaudio = []; for(var i = 0; i < data.nvaudio.length ; i++){ this.nvaudio.push( cc.url.raw("resources/"+data.nvaudio[i]+".mp3" )); } } },yingyuep(id){ if (!this.audioSource|| ! this.audioSource[id] ) return; this.audioSource[id].volume = this._YingLiang ; this.audioSource[id].play(); },yingyuet(id){ if (!this.audioSource|| ! this.audioSource[id] ) return; this.audioSource[id].stop(); },yingyuez(id){ if (!this.audioSource|| ! this.audioSource[id] ) return; this.audioSource[id].pause(); },yingyuec(id){ if (!this.audioSource|| ! this.audioSource[id] ) return; this.audioSource[id].resume(); },yingyueallstop(){ if (!this.audioSource || this._YingLiang <= 0 ) return; for(var i = 0; i  1){
            num = 1;
        }else if(num <=0){ num = 0.0; } this._YingXiao = num; cc.sys.localStorage.setItem('yingxiao',num); },setyingyue(num){ num = parseFloat(num); if(num > 1){
            num = 1;
        }else if(num <=0){ num = 0.0; } this._YingLiang = num; this.yingyueallsetnum(); cc.sys.localStorage.setItem('yingyue',num); },duqu(){ return [this._YingLiang,this._YingXiao]; } }); 
客服 反馈