update method

void update(
  1. double dt
)

Updates this animation, if not paused, ticking the lifeTime by an amount dt (in seconds).

Implementation

void update(double dt) {
  if (_paused) {
    return;
  }
  clock += dt;
  elapsed += dt;
  if (_done) {
    return;
  }
  if (!_started) {
    onStart?.call();
    onFrame?.call(currentIndex);
    _started = true;
  }

  while (clock >= currentFrame.stepTime) {
    if (isLastFrame) {
      if (spriteAnimation.loop) {
        clock -= currentFrame.stepTime;
        currentIndex = 0;
        onFrame?.call(currentIndex);
      } else {
        _done = true;
        onComplete?.call();
        completeCompleter?.complete();
        return;
      }
    } else {
      clock -= currentFrame.stepTime;
      currentIndex++;
      onFrame?.call(currentIndex);
    }
  }
}