advance method

  1. @override
bool advance(
  1. FlutterActorArtboard artboard,
  2. double elapsed
)
override

Advance all the FlareAnimationLayers that are currently controlled by this object, and mixes them accordingly.

If an animation completes during the current frame (and doesn't loop), the onCompleted() callback will be triggered.

Implementation

@override
bool advance(FlutterActorArtboard artboard, double elapsed) {
  assert(artboard == _artboard);

  /// List of completed animations during this frame.
  List<FlareAnimationLayer> completed = [];

  /// This loop will mix all the currently active animation layers so that,
  /// if an animation is played on top of the current one, it'll smoothly mix
  ///  between the two instead of immediately switching to the new one.
  for (int i = 0; i < _animationLayers.length; i++) {
    FlareAnimationLayer layer = _animationLayers[i];
    layer.mix += elapsed;
    layer.time += elapsed;

    double mix = _mixSeconds == 0.0 ? 1.0 : min(1.0, layer.mix / _mixSeconds);

    /// Loop the time if needed.
    if (layer.animation.isLooping) {
      layer.time %= layer.animation.duration;
    }

    /// Apply the animation with the current mix.
    layer.animation.apply(layer.time, artboard, mix);

    /// Add (non-looping) finished animations to the list.
    if (layer.time > layer.animation.duration) {
      completed.add(layer);
    }
  }

  /// Notify of the completed animations.
  for (final FlareAnimationLayer animation in completed) {
    _animationLayers.remove(animation);
    onCompleted(animation.name);
  }
  return _animationLayers.isNotEmpty;
}