Commit 4c1a0b98 authored by liujiangnan's avatar liujiangnan

feat: 定时器释放

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