2014-04-07 136 views
0

我想在某個事件被觸發後重置我的計時器。目前,我有我在遊戲中的計時器,它會檢查該事件每4秒在我的更新內容如下:重置計時器在impactjs

timer: new ig.Timer(), 
update:function(){ 
      //console.log(this.timer.delta()); 
      if (this.timer.delta() >= 0) { 
       this.performAchievementChecks(); 
       this.timer.set(4); 
      } 
}, 

performAchievementChecks:function(){ 
      if(tempArray.length >= 1 && this.Achievements[achID].status == this.storage.get(achKey)){ 
       this.performUpdate(achID); 
      } 
} 

    performUpdate:function(achID){ 
      this.timer.set(0); 
      this.updateAchievements(achID); 
    } 

所以我的功能performAchievementchecks()被稱爲每4秒,在這段時間內如果if語句去true後來我想重置我的計時器回到0,但它不這樣做。有人能指出我做錯了什麼嗎?如果是這樣,在update()之外的某個事件發生時,如何從其他不同的函數重置我的遊戲計時器?

回答

0

我不知道你是什麼意思「復位我的定時器回到0」,如果你只希望定時器重置,你沒有做任何事情,因爲你已經設置this.timer.set(4);,另一個選項是禁用它,爲此,您可以簡單地將該變量設置爲null。

提示:

1.You可以與目標直接創建定時器:

timer: new ig.Timer(4) 

然後用this.timer.reset();重啓定時器。

2.You可以設置定時器變量爲null this.timer = null;如果要禁用它,並檢查變量在更新funstion分配:

if (this.timer && this.timer.delta() >= 0) { ... } 

PS:檢查影響文檔上的計時器here