| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- cc.Class({
- extends: cc.Component,
- properties: {
- },
- play(name)
- {
- let self = this;
- cc.loader.loadRes(name, cc.AudioClip, (err, audioClip)=> {
- self.currentAudio = cc.audioEngine.play(audioClip, false, 1);
- });
- },
- playAudio(name,callback)
- {
- let self = this;
- cc.loader.loadRes(name, cc.AudioClip, (err, audioClip)=> {
- self.currentAudio = cc.audioEngine.play(audioClip, false, 1);
- cc.audioEngine.setFinishCallback(self.currentAudio, function ()
- {
- callback();
- });
- });
- },
- playAudioBySequence(arr,callback)
- {
- let self = this;
- let aIndex = 0;
- let playDemonstrationAudio = function () {
- if(aIndex == arr.length)
- {
- callback();
- return;
- }
- if(typeof arr[aIndex] === "number")
- {
- self.playNumAudio(arr[aIndex],function () {
- aIndex++;
- playDemonstrationAudio();
- });
- }
- else
- {
- self.playAudio(arr[aIndex],playDemonstrationAudio);
- aIndex++;
- }
- };
- playDemonstrationAudio(arr[aIndex],playDemonstrationAudio);
- },
- playNumAudio(num,callback)
- {
- if(num == 15)
- {
- this.playAudio('Audios/Game/Others/一组15秒',callback);
- }
- else if(num == 20)
- {
- this.playAudio('Audios/Game/Others/一组20秒',callback);
- }
- else if(num == 25)
- {
- this.playAudio('Audios/Game/Others/一组25秒',callback);
- }
- else if(num == 30)
- {
- this.playAudio('Audios/Game/Others/一组30秒',callback);
- }
- // let numArr = [];
- // this.appendNum(num,numArr);
- //
- // let aIndex = 0;
- // let playNum = function () {
- // if(aIndex == numArr.length)
- // {
- // this.unschedule(playNum);
- // // console.log('22222')
- // this.scheduleOnce(function () {
- // callback();
- // }, 0.3);
- //
- // return;
- // }
- // this.play(numArr[aIndex]);
- // aIndex++;
- // };
- // this.schedule(playNum, 0.3);
- },
- appendNum(num,arr)
- {
- if(num == 10)
- {
- arr.push('Audios/Game/Nums/10');
- return;
- }
- if(num > 10 && num < 20)
- {
- let str = num.toString();
- arr.push('Audios/Game/Nums/10');
- arr.push('Audios/Game/Nums/'+str.substr(1,1));
- return;
- }
- let str = num.toString();
- arr.push('Audios/Game/Nums/'+str.substr(0,1));
- if(str.length>1)
- {
- arr.push('Audios/Game/Nums/10');
- if(str.substr(1,1)!='0')
- {
- arr.push('Audios/Game/Nums/'+str.substr(1,1));
- }
- }
- }
- });
|