Commit 561ced30 authored by Friends233's avatar Friends233

修改定时器

parent aa07dd0d
...@@ -81,6 +81,8 @@ export default class GameScene extends cc.Component { ...@@ -81,6 +81,8 @@ export default class GameScene extends cc.Component {
/** 加速倍率 */ /** 加速倍率 */
speedMultiplier = 1 speedMultiplier = 1
timer = null
protected onLoad(): void { protected onLoad(): void {
// loadGameResources() // loadGameResources()
...@@ -183,7 +185,8 @@ export default class GameScene extends cc.Component { ...@@ -183,7 +185,8 @@ export default class GameScene extends cc.Component {
this.startGameCountAni(() => { this.startGameCountAni(() => {
this.isStartGame = true this.isStartGame = true
cc.find('clipMask/clipWrp', this.node).getComponent(cc.Animation).play() cc.find('clipMask/clipWrp', this.node).getComponent(cc.Animation).play()
this.schedule(this.startCd, 1) // this.schedule(this.startCd, 1)
this.timer = setInterval(() => this.startCd(), 1000)
}) })
} }
...@@ -301,6 +304,7 @@ export default class GameScene extends cc.Component { ...@@ -301,6 +304,7 @@ export default class GameScene extends cc.Component {
this.isGameOver = true this.isGameOver = true
this.setClipState(CLIP_STATE.GAME_OVER) this.setClipState(CLIP_STATE.GAME_OVER)
this.unschedule(this.startCd) this.unschedule(this.startCd)
window.clearInterval(this.timer)
exportEvent.fire(CUSTOM_EVENT.GAME_OVER, { exportEvent.fire(CUSTOM_EVENT.GAME_OVER, {
...this.gameConfig.LevelInfo[this.actLevel], ...this.gameConfig.LevelInfo[this.actLevel],
score: this.starNum, score: this.starNum,
...@@ -323,6 +327,7 @@ export default class GameScene extends cc.Component { ...@@ -323,6 +327,7 @@ export default class GameScene extends cc.Component {
this.setLable('cdIcon/cd', `0s`) this.setLable('cdIcon/cd', `0s`)
this.gameOver() this.gameOver()
this.unschedule(this.startCd) this.unschedule(this.startCd)
window.clearInterval(this.timer)
return return
} }
this.countDown = cd this.countDown = cd
...@@ -331,6 +336,7 @@ export default class GameScene extends cc.Component { ...@@ -331,6 +336,7 @@ export default class GameScene extends cc.Component {
protected onDestroy(): void { protected onDestroy(): void {
this.unschedule(this.startCd) this.unschedule(this.startCd)
window.clearInterval(this.timer)
} }
/** 刷新关卡信息 */ /** 刷新关卡信息 */
...@@ -352,6 +358,7 @@ export default class GameScene extends cc.Component { ...@@ -352,6 +358,7 @@ export default class GameScene extends cc.Component {
this.updateGameProc() this.updateGameProc()
this.unschedule(this.startCd) this.unschedule(this.startCd)
window.clearInterval(this.timer)
this.setLable('cdIcon/cd', `${this.countDown}s`) this.setLable('cdIcon/cd', `${this.countDown}s`)
} }
...@@ -372,6 +379,7 @@ export default class GameScene extends cc.Component { ...@@ -372,6 +379,7 @@ export default class GameScene extends cc.Component {
if (this.starNum >= this.levelObjectives) { if (this.starNum >= this.levelObjectives) {
this.isStartGame = false this.isStartGame = false
this.unschedule(this.startCd) this.unschedule(this.startCd)
window.clearInterval(this.timer)
exportEvent.fire(CUSTOM_EVENT.PASS_LEVEL, { exportEvent.fire(CUSTOM_EVENT.PASS_LEVEL, {
...this.gameConfig.LevelInfo[this.actLevel], ...this.gameConfig.LevelInfo[this.actLevel],
score: this.starNum, score: this.starNum,
...@@ -386,13 +394,15 @@ export default class GameScene extends cc.Component { ...@@ -386,13 +394,15 @@ export default class GameScene extends cc.Component {
const nextLevel = this.actLevel + 1 const nextLevel = this.actLevel + 1
this.isStartGame = true this.isStartGame = true
this.unschedule(this.startCd) this.unschedule(this.startCd)
window.clearInterval(this.timer)
if (nextLevel >= this.gameConfig.LevelInfo.length) { // 已通关 if (nextLevel >= this.gameConfig.LevelInfo.length) { // 已通关
this.gameOver() this.gameOver()
return return
} }
this.refreshLevelInfo(nextLevel) this.refreshLevelInfo(nextLevel)
this.refreshStageProps() this.refreshStageProps()
this.schedule(this.startCd, 1) // this.schedule(this.startCd, 1)
this.timer = setInterval(() => this.startCd(), 1000)
} }
/** 更新游戏进度条信息 */ /** 更新游戏进度条信息 */
......
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