sprite method
Returns a Sprite for the given spriteId.
Throws an Exception if the sprite is not found in the atlas.
Implementation
Sprite sprite(String spriteId) {
final spriteData = atlas.sprites[spriteId];
if (spriteData == null) {
throw Exception('Sprite $spriteId not found in the atlas');
}
final paddedTileSize = tileSize + padding;
final srcPosition = Vector2(
spriteData.$1 * paddedTileSize + padding / 2,
spriteData.$2 * paddedTileSize + padding / 2,
);
final srcSize = Vector2(
(spriteData.$3 ?? 1) * tileSize,
(spriteData.$4 ?? 1) * tileSize,
);
return Sprite(
image,
srcPosition: srcPosition,
srcSize: srcSize,
);
}