load static method

Future<ParallaxAnimation> load(
  1. String path,
  2. SpriteAnimationData animationData, {
  3. ImageRepeat repeat = ImageRepeat.repeatX,
  4. Alignment alignment = Alignment.bottomLeft,
  5. LayerFill fill = LayerFill.height,
  6. Images? images,
  7. FilterQuality? filterQuality,
})

Takes a path of an image, a SpriteAnimationData, and optionally arguments for how the image should repeat (repeat), which edge it should align with (alignment), which axis it should fill the image on (fill) and images which is the image cache that should be used. If no image cache is set, the global flame cache is used.

IMPORTANT: This method pre render all the frames of the animation into image instances so it can be used inside the parallax. Just keep that in mind when using animations in parallax, the over use of it, or the use of big animations (be it in number of frames or the size of the images) can lead to high use of memory.

Implementation

static Future<ParallaxAnimation> load(
  String path,
  SpriteAnimationData animationData, {
  ImageRepeat repeat = ImageRepeat.repeatX,
  Alignment alignment = Alignment.bottomLeft,
  LayerFill fill = LayerFill.height,
  Images? images,
  FilterQuality? filterQuality,
}) async {
  images ??= Flame.images;

  final animation =
      await SpriteAnimation.load(path, animationData, images: images);
  final prerenderedFrames =
      animation.frames.map((frame) => frame.sprite.toImageSync()).toList();

  return ParallaxAnimation(
    animation,
    prerenderedFrames,
    repeat: repeat,
    alignment: alignment,
    fill: fill,
    filterQuality: filterQuality,
  );
}