getFutureSprite static method

Future<Sprite> getFutureSprite(
  1. String image, {
  2. int row = 0,
  3. int column = 0,
  4. double tileWidth = 0,
  5. double tileHeight = 0,
})

Implementation

static Future<Sprite> getFutureSprite(
  String image, {
  int row = 0,
  int column = 0,
  double tileWidth = 0,
  double tileHeight = 0,
}) async {
  if (spriteCache.containsKey('$image/$row/$column')) {
    return Future.value(spriteCache['$image/$row/$column']);
  }

  Image spriteSheetImg = await loadImage(
    image,
  );

  return spriteCache['$image/$row/$column'] = spriteSheetImg.getSprite(
    position: Vector2(
      (column * tileWidth).toDouble(),
      (row * tileHeight).toDouble(),
    ),
    size: Vector2(
      tileWidth == 0.0 ? spriteSheetImg.width.toDouble() : tileWidth,
      tileHeight == 0.0 ? spriteSheetImg.height.toDouble() : tileHeight,
    ),
  );
}