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 they all the frames happen to be sequentially on the same row. Sprites are lazily generated but cached.

Constructors

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

Properties

columns int
Compute the number of columns the image has by using the image width and tile size.
no setter
hashCode int
The hash code for this object.
no setterinherited
image Image
The src image from which each sprite will be generated.
final
rows int
Compute the number of rows the image has by using the image height and tile size.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
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.
getSprite(int row, int column) Sprite
Gets the sprite in the position (row, column) on the sprite sheet grid.
getSpriteById(int spriteId) Sprite
Gets teh 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