cc.Class({ extends: cc.Component, properties: { bgClip: { default: null, type: cc.AudioClip }, tipClip: { default: [], type: cc.AudioClip, tooltip: "提示出拳方式, 0 左,1 中,2 右", }, //游戏开始 gameStart: { default: null, type: cc.AudioClip }, gameVictory: { default: null, tooltip: "游戏胜利", type: cc.AudioClip }, gameDefeat: { default: null, tooltip: "游戏失败", type: cc.AudioClip }, numClip: { default: [], type: cc.AudioClip, tooltip: "播报数字0 - 10", }, numPower: { default: null, tooltip: "数值前的力量提示", type: cc.AudioClip }, numUnit: { default: null, tooltip: "数值后的单位", type: cc.AudioClip }, hitFail: { default: null, tooltip: "击打失败", type: cc.AudioClip }, hitSuccess: { default: null, tooltip: "击打成功", type: cc.AudioClip }, getCoin: { default: null, tooltip: "获得金币", type: cc.AudioClip }, deducCoin: { default: null, tooltip: "扣金币", type: cc.AudioClip }, noCoin: { default: null, tooltip: "不够金币", type: cc.AudioClip }, threeHits: { default: null, tooltip: "连续击中三次", type: cc.AudioClip }, twoHits: { default: null, tooltip: "连续击中两次", type: cc.AudioClip }, }, // LIFE-CYCLE CALLBACKS: onLoad() { window.myAudio = this; }, start() { cc.audioEngine.playMusic(this.bgClip, true); // this.onPlayHitPower("48"); }, //提示出拳方式, 0 左,1 中,2 右 onPlayBoxingTip(tipIndex) { cc.audioEngine.play(this.tipClip[tipIndex], false, 1); }, //开始转动 onPlayGameStart(callback) { cc.audioEngine.play(this.gameStart, false, 1); setTimeout(() => { if (callback) callback(); }, 2000); }, onPlayGameVictory() { cc.audioEngine.play(this.gameVictory, false, 1); }, onPlayGameDefeat() { cc.audioEngine.play(this.gameDefeat, false, 1); }, onPlayHitPower(hitPower, callback) { let hitPowers = hitPower.split(''); // console.log("onPlayHitPower", hitPowers); let self = this; let audioIndexArray = []; if (hitPower.length == 3) { //三位数 audioIndexArray.push(hitPowers[0]);//百 audioIndexArray.push(11);//插入百的单位声音 //如果十位是0的话,也不用插入读音 if (hitPowers[1] !== "0") audioIndexArray.push(hitPowers[1]);//十 audioIndexArray.push(10);//插入十的单位声音 //假如最后一个是 0 ,不用插入 if (hitPowers[2] !== "0") audioIndexArray.push(hitPowers[2]);//个 } else if (hitPower.length == 2) { //两位数 audioIndexArray.push(hitPowers[0]);//十 audioIndexArray.push(10);//插入十的单位声音 //假如最后一个是 0 ,不用插入 if (hitPowers[1] !== "0") audioIndexArray.push(hitPowers[1]);//个 } cc.audioEngine.play(self.numPower, false, 1); setTimeout(function () { for (let i = 0; i < audioIndexArray.length; i++) { ( function (a) { setTimeout(function () { cc.audioEngine.play(self.numClip[audioIndexArray[a]], false, 1); if (a == audioIndexArray.length - 1) { setTimeout(function () { cc.audioEngine.play(self.numUnit, false, 1); //读完后给个回调 setTimeout(function () { if (callback) callback(); }, 1000) }, 500) } }, a * 500) }(i) ) } }, 1300) }, onHitFail() { cc.audioEngine.playEffect(this.hitFail, false, 1); }, onHitSuccess() { cc.audioEngine.playEffect(this.hitSuccess, false, 1); }, onGetCoin() { cc.audioEngine.playEffect(this.getCoin, false, 1); }, onDeducCoin() { cc.audioEngine.playEffect(this.deducCoin, false, 1); }, onNoCoin() { cc.audioEngine.playEffect(this.noCoin, false, 1); }, onTwoHits() { cc.audioEngine.playEffect(this.twoHits, false, 1); }, onThreeHits() { cc.audioEngine.playEffect(this.threeHits, false, 1); } // update (dt) {}, });