advance method

  1. @override
void advance(
  1. double elapsedSeconds
)
inherited

Advance animations, physics, etc by elapsedSeconds.

Implementation

@override
void advance(double elapsedSeconds) {
  if (isPlaying) {
    int lastFullyMixed = -1;
    double lastMix = 0.0;

    List<FlareAnimationLayer> completed = [];

    for (int i = 0; i < _animationLayers.length; i++) {
      FlareAnimationLayer layer = _animationLayers[i];

      if (snapToEnd && !layer.animation.isLooping) {
        layer.mix = 1.0;
        layer.time = layer.duration;
      } else {
        layer.mix += elapsedSeconds;
        layer.time += elapsedSeconds;
      }

      lastMix = layer.mixSeconds == 0.0
          ? 1.0
          : min(1.0, layer.mix / layer.mixSeconds);
      if (layer.animation.isLooping) {
        layer.time %= layer.animation.duration;
      }
      layer.animation.apply(layer.time, _artboard, lastMix);
      if (lastMix == 1.0) {
        lastFullyMixed = i;
      }
      if (layer.time > layer.animation.duration) {
        completed.add(layer);
      }
    }

    if (lastFullyMixed != -1) {
      _animationLayers.removeRange(0, lastFullyMixed);
    }
    if (animationName == null &&
        _animationLayers.length == 1 &&
        lastMix == 1.0) {
      // Remove remaining animations.
      _animationLayers.removeAt(0);
    }
    for (final FlareAnimationLayer animation in completed) {
      _animationLayers.remove(animation);
      if (_completedCallback != null) {
        _completedCallback!(animation.name);
      }
    }
  }

  if (_actor != null &&
      _controller != null &&
      !_controller!.advance(_artboard, elapsedSeconds)) {
    _controller?.isActive.value = false;
  }

  // artboard is gauranteed to be available once actor is
  if (_actor != null) {
    _artboard.advance(elapsedSeconds);
  }
}