2014-04-07 137 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