From af228ac28322823968dab0a37b2ececeb2d0adec Mon Sep 17 00:00:00 2001 From: liujiangnan <695541723@qq.com> Date: Sun, 19 Dec 2021 17:36:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8A=E6=94=BE=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Sbox_FT_08/script/GameLogic.js | 33 +++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/assets/Sbox_FT_08/script/GameLogic.js b/assets/Sbox_FT_08/script/GameLogic.js index 63d8e3a..5ac71f3 100644 --- a/assets/Sbox_FT_08/script/GameLogic.js +++ b/assets/Sbox_FT_08/script/GameLogic.js @@ -263,10 +263,10 @@ export default class GameLogic { this.g_cartoon.getCartoonElement("bird_1").wrong() this.g_cartoon.getCartoonElement("bird_2").wrong() this.g_cartoon.playAudio("try_again", ()=>{ - setTimeout(()=>{ + this._timeoutIds.push(setTimeout(()=>{ this.g_cartoon.playAudio(this.g_formData.dataArray[this.m_currentQuestion].audio_url) this.enableClick(`card_${index+1}_image_container`) - }, 1000) + }, 1000)) }) } else { this.enableClick(`card_${index+1}_image_container`) @@ -346,11 +346,11 @@ export default class GameLogic { }) this.g_cartoon.tweenChange(bell2.node, {scaleX: 1, scaleY: 1}, 0.2, ()=>{ this.g_cartoon.getCartoonElement("bird_1").flyBack(()=>{ - setTimeout(()=>{ + this._timeoutIds(setTimeout(()=>{ if(callback) { callback(); } - }, 1500) + }, 1500)) }) this.g_cartoon.getCartoonElement("bird_2").flyBack() }); @@ -699,21 +699,21 @@ export default class GameLogic { birdAniWrong_1.node.opacity = 255; birdStatic_1.node.opacity = 0; birdAudio.switchAni(1) - setTimeout(() => { + this._timeoutIds(setTimeout(() => { birdAniWrong_1.node.opacity = 0; birdStatic_1.node.opacity = 255; birdAudio.switchAni(0) - }, 1000); + }, 1000)); } bird_2.wrong = ()=>{ birdAniWrong_2.node.opacity = 255; birdStatic_2.node.opacity = 0; - setTimeout(() => { + this._timeoutIds(setTimeout(() => { birdAniWrong_2.node.opacity = 0; birdStatic_2.node.opacity = 255; - }, 1000); + }, 1000)); } bird_1.node.y = -cc.winSize.height / 2 + bird_1.node.height + 10 @@ -762,16 +762,24 @@ export default class GameLogic { const downTime = Math.ceil((cc.winSize.height / 100) * 1000) / 1000 console.log(downTime) - this.intervalID = setInterval(() => { + this._intervalIds(setInterval(() => { let snow = getSnow( Math.ceil(Math.random()*4) ) // this.g_cartoon.tweenChange(snow, {y: -cc.winSize.height / 2}, downTime) cc.tween(snow).to(downTime, {y: -cc.winSize.height / 2}).call(()=>snow.destroy()).start() - }, 100); + }, 100)); } + _timeoutIds = [] + _intervalIds = [] + // 生命周期 destroy() { - clearInterval(this.intervalID); + this._timeoutIds.forEach(id => { + clearTimeout(id); + }); + this._intervalIds.forEach(id => { + clearInterval(id); + }); } @@ -783,9 +791,6 @@ export default class GameLogic { - - - // Common function maskLayer = null; initMaskLayer() { -- 2.21.0