AnimatedSprite.fromUniformSpriteSheet constructor

AnimatedSprite.fromUniformSpriteSheet({
  1. required String imagePath,
  2. required IntSize spriteSize,
  3. required IntRect atlasBounds,
  4. required double frameDuration,
  5. required Transform2D transform,
  6. Color color = const Color(0x00000000),
})

Load an animation from a uniform sprite sheet given size and bounds

image the image name spriteSize the size of the sub-images inside the sprite sheet atlasBounds the bounds of the num of sprites inside the sheet frameDuration the duration per frame color an optional color per frame transform the animation transform .. could add per-frame-transform and duration .. move outside class/file?

Implementation

factory AnimatedSprite.fromUniformSpriteSheet({
  required String imagePath,
  required IntSize spriteSize,
  required IntRect atlasBounds,
  required double frameDuration,
  required Transform2D transform,
  Color color = const Color(0x00000000),
}) {
  List<Frame> frames = [];
  for (int row = atlasBounds.top; row < atlasBounds.height; row++) {
    for (int col = atlasBounds.left; col < atlasBounds.width; col++) {
      frames.add(
        Frame(
          duration: frameDuration,
          sprite: Sprite(
            transform: Transform2D(),
            imagePath: imagePath,
            color: color,
            rect: IntRect(
              left: col * spriteSize.width,
              top: row * spriteSize.height,
              width: spriteSize.width,
              height: spriteSize.height,
            ),
          ),
        ),
      );
    }
  }
  return AnimatedSprite(
    imagePath: imagePath,
    transform: transform,
    frames: frames,
  );
}