Commit 4c1a0b98 authored by liujiangnan's avatar liujiangnan

feat: 定时器释放

parent 9858b172
......@@ -88,6 +88,8 @@ cc.Class({
onDestory() {
cc.audioEngine.stopAll()
this.gameLogic.destroy()
},
getData(func) {
......
......@@ -174,13 +174,24 @@ export default class Cartoon {
}
}
_timeoutIds = []
_intervalIds = []
destroy() {
this._timeoutIds.forEach(id => {
clearTimeout(id);
});
this._intervalIds.forEach(id => {
clearInterval(id);
});
}
playVideo(videoPlayer, callback) {
if(videoPlayer && videoPlayer.isPlaying) {
videoPlayer.stop()
}
if(videoPlayer) {
setTimeout(()=>{
this._timeoutIds(setTimeout(()=>{
videoPlayer.play()
videoPlayer.node.off("completed")
videoPlayer.node.on("completed", ()=>{
......@@ -188,7 +199,7 @@ export default class Cartoon {
callback()
}
})
}, 50)
}, 50))
}
}
......
......@@ -452,16 +452,16 @@ export default class GameLogic {
if(this.m_currentQuestion >= this.g_formData.dataArray.length) {
this.m_currentQuestion = this.g_formData.dataArray.length-1
return new Promise((resolve, reject) => {
setTimeout(() => {
this._timeoutIds(setTimeout(() => {
resolve(false)
}, 20);
}, 20));
});
} else if(this.m_currentQuestion <= -1) {
this.m_currentQuestion = 0;
return new Promise((resolve, reject) => {
setTimeout(() => {
this._timeoutIds(setTimeout(() => {
resolve(false)
}, 20);
}, 20));
});
}
......@@ -720,4 +720,16 @@ export default class GameLogic {
console.log(`Click enabled! [${eventName}]`)
}
_timeoutIds = []
_intervalIds = []
destroy() {
this.g_cartoon.destroy();
this._timeoutIds.forEach(id => {
clearTimeout(id);
});
this._intervalIds.forEach(id => {
clearInterval(id);
});
}
}
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