Dart Documentationgame_loopGameLoopTimer

GameLoopTimer class

A cancellable timer that calls a GameLoopTimerFunction when it fires. A timer can only fire once, afterwards it is dead.

class GameLoopTimer {
 /** Game loop timer was created by */
 final GameLoop gameLoop;
 /** Callback function that will be call when timer fires. */
 final GameLoopTimerFunction onTimer;
 double _timeToFire = 0.0;
 /** Time until timer fires. */
 double get timeToFire => _timeToFire;
 GameLoopTimer._internal(this.gameLoop, this._timeToFire, this.onTimer);
 void _update(double dt) {
   if (_timeToFire <= 0.0) {
     // Dead.
     return;
   }
   _timeToFire -= dt;
   if (_timeToFire <= 0.0) {
     if (onTimer != null) {
       onTimer(this);
     }
   }
 }

 bool get _dead => _timeToFire <= 0.0;

 /** Cancel the timer. */
 void cancel() {
   _timeToFire = -1.0;
 }
}

Properties

final GameLoop gameLoop #

gameLoop

final GameLoopTimerFunction onTimer #

onTimer

final double timeToFire #

Time until timer fires.

double get timeToFire => _timeToFire;

Methods

void cancel() #

Cancel the timer.

void cancel() {
 _timeToFire = -1.0;
}