getSprite method
Returns a Sprite with the given selectionId
.
Implementation
Sprite getSprite(String selectionId) {
final selection = selections[selectionId];
if (selection == null) {
throw 'There is no selection with the id "$selectionId" on this atlas';
}
if (selection is! SpriteSelection) {
throw 'Selection "$selectionId" is not a Sprite';
}
final image = _assertImageLoaded();
return Sprite(
image,
srcPosition: Vector2(
selection.x.toDouble() * tileWidth,
selection.y.toDouble() * tileHeight,
),
srcSize: Vector2(
(1 + selection.w.toDouble()) * tileWidth,
(1 + selection.h.toDouble()) * tileHeight,
),
);
}