SpriteSheet class

Utility class to help extract animations and sprites from a sprite sheet image.

A sprite sheet is a single image in which several regions can be defined as individual sprites. For the purposes of this class, all of these regions must be identically sized rectangles. You can use the Sprite class directly if you want to have varying shapes.

Each sprite in this sheet can be identified either by it's (row, col) pair or by it's "id", which is basically it's sequenced index if the image is put in a single line. The sprites can be used to compose an animation easily if all the frames are sequentially on the same row. Sprites are lazily generated but cached.

Constructors

SpriteSheet({required Image image, required Vector2 srcSize, double margin = 0, double spacing = 0})
Creates a sprite sheet given the image and the tile size.
SpriteSheet.fromColumnsAndRows({required Image image, required int columns, required int rows, double spacing = 0, double margin = 0})

Properties

columns int
The number of columns in the image based on the image width and the tile size.
final
hashCode int
The hash code for this object.
no setterinherited
image Image
The src image from which each sprite will be generated.
final
margin double
The empty space around the edges of the image.
final
rows int
The number of rows in the image based on the image height and the tile size.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
spacing double
This empty space in between adjacent tiles within the image.
final
srcSize Vector2
The size of each rectangle within the image that define each sprite.
final

Methods

createAnimation({required int row, required double stepTime, bool loop = true, int from = 0, int? to}) SpriteAnimation
Creates a SpriteAnimation from this SpriteSheet, using the sequence of sprites on a given row.
createAnimationWithVariableStepTimes({required int row, required List<double> stepTimes, bool loop = true, int from = 0, int? to}) SpriteAnimation
Creates a SpriteAnimation from this SpriteSheet, using the sequence of sprites on a given row with different duration for each.
createFrameData(int row, int column, {required double stepTime}) SpriteAnimationFrameData
Create a SpriteAnimationFrameData for the sprite in the position (row, column) on the sprite sheet grid.
createFrameDataFromId(int spriteId, {required double stepTime}) SpriteAnimationFrameData
Create a SpriteAnimationFrameData for the sprite with id spriteId from the grid.
getSprite(int row, int column) Sprite
Gets the sprite in the position (row, column) on the sprite sheet grid.
getSpriteById(int spriteId) Sprite
Gets the sprite with id spriteId from the grid.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited