Commit af228ac2 authored by liujiangnan's avatar liujiangnan

feat: 释放定时器

parent b20cd983
...@@ -263,10 +263,10 @@ export default class GameLogic { ...@@ -263,10 +263,10 @@ export default class GameLogic {
this.g_cartoon.getCartoonElement("bird_1").wrong() this.g_cartoon.getCartoonElement("bird_1").wrong()
this.g_cartoon.getCartoonElement("bird_2").wrong() this.g_cartoon.getCartoonElement("bird_2").wrong()
this.g_cartoon.playAudio("try_again", ()=>{ 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.g_cartoon.playAudio(this.g_formData.dataArray[this.m_currentQuestion].audio_url)
this.enableClick(`card_${index+1}_image_container`) this.enableClick(`card_${index+1}_image_container`)
}, 1000) }, 1000))
}) })
} else { } else {
this.enableClick(`card_${index+1}_image_container`) this.enableClick(`card_${index+1}_image_container`)
...@@ -346,11 +346,11 @@ export default class GameLogic { ...@@ -346,11 +346,11 @@ export default class GameLogic {
}) })
this.g_cartoon.tweenChange(bell2.node, {scaleX: 1, scaleY: 1}, 0.2, ()=>{ this.g_cartoon.tweenChange(bell2.node, {scaleX: 1, scaleY: 1}, 0.2, ()=>{
this.g_cartoon.getCartoonElement("bird_1").flyBack(()=>{ this.g_cartoon.getCartoonElement("bird_1").flyBack(()=>{
setTimeout(()=>{ this._timeoutIds(setTimeout(()=>{
if(callback) { if(callback) {
callback(); callback();
} }
}, 1500) }, 1500))
}) })
this.g_cartoon.getCartoonElement("bird_2").flyBack() this.g_cartoon.getCartoonElement("bird_2").flyBack()
}); });
...@@ -699,21 +699,21 @@ export default class GameLogic { ...@@ -699,21 +699,21 @@ export default class GameLogic {
birdAniWrong_1.node.opacity = 255; birdAniWrong_1.node.opacity = 255;
birdStatic_1.node.opacity = 0; birdStatic_1.node.opacity = 0;
birdAudio.switchAni(1) birdAudio.switchAni(1)
setTimeout(() => { this._timeoutIds(setTimeout(() => {
birdAniWrong_1.node.opacity = 0; birdAniWrong_1.node.opacity = 0;
birdStatic_1.node.opacity = 255; birdStatic_1.node.opacity = 255;
birdAudio.switchAni(0) birdAudio.switchAni(0)
}, 1000); }, 1000));
} }
bird_2.wrong = ()=>{ bird_2.wrong = ()=>{
birdAniWrong_2.node.opacity = 255; birdAniWrong_2.node.opacity = 255;
birdStatic_2.node.opacity = 0; birdStatic_2.node.opacity = 0;
setTimeout(() => { this._timeoutIds(setTimeout(() => {
birdAniWrong_2.node.opacity = 0; birdAniWrong_2.node.opacity = 0;
birdStatic_2.node.opacity = 255; birdStatic_2.node.opacity = 255;
}, 1000); }, 1000));
} }
bird_1.node.y = -cc.winSize.height / 2 + bird_1.node.height + 10 bird_1.node.y = -cc.winSize.height / 2 + bird_1.node.height + 10
...@@ -762,16 +762,24 @@ export default class GameLogic { ...@@ -762,16 +762,24 @@ export default class GameLogic {
const downTime = Math.ceil((cc.winSize.height / 100) * 1000) / 1000 const downTime = Math.ceil((cc.winSize.height / 100) * 1000) / 1000
console.log(downTime) console.log(downTime)
this.intervalID = setInterval(() => { this._intervalIds(setInterval(() => {
let snow = getSnow( Math.ceil(Math.random()*4) ) let snow = getSnow( Math.ceil(Math.random()*4) )
// this.g_cartoon.tweenChange(snow, {y: -cc.winSize.height / 2}, downTime) // 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() cc.tween(snow).to(downTime, {y: -cc.winSize.height / 2}).call(()=>snow.destroy()).start()
}, 100); }, 100));
} }
_timeoutIds = []
_intervalIds = []
// 生命周期
destroy() { destroy() {
clearInterval(this.intervalID); this._timeoutIds.forEach(id => {
clearTimeout(id);
});
this._intervalIds.forEach(id => {
clearInterval(id);
});
} }
...@@ -783,9 +791,6 @@ export default class GameLogic { ...@@ -783,9 +791,6 @@ export default class GameLogic {
// Common function // Common function
maskLayer = null; maskLayer = null;
initMaskLayer() { initMaskLayer() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment