SpriteSheet class
An ImageFrameProvider that works with basic sprite sheets or single frame
images. It can accept an unloaded ImageProvider, and toggle isReady
when
it successfully loads.
Single frame images
Simply pass in the image
. The frame width/height will be calculated automatically,
and length will be set to 1.
Image strips
For a horizontal strip of frames, specify the image
and a frameWidth
.
The image's intrinsic height will be used for frameHeight
, and length
will
be calculated by dividing the image width by the frame width. Vertical strips
can specify a frameHeight
instead of width.
Image grid
Specify the image
, frameWidth
, and frameHeight
. The length
can be
calculated automatically with this information from the image's intrinsic
dimensions, but you can also provide a length to limit it (ex. if the grid
is not totally filled, such as 13 frames in a 3x5 grid).
Texture packing
Variable sized frames aren't currently supported by this class, but an implementation could be written that implements ImageFrameProvider.
Example
For example, the sparkle sprite sheet included with the example, is a horizontal strip of 13 frames at 21x23px (273px wide in total):
SpriteSheet(
image: AssetImage('sparkles.png'),
frameWidth: 21,
)
The frame height and length aren't necessary because they are calculated from the image's intrinsic dimensions.
- Mixed-in types
Constructors
-
SpriteSheet({required ImageProvider<
Object> image, int frameWidth = 0, int frameHeight = 0, int length = 0, double scale = 1.0})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- image → Image
-
Returns the image to use when drawing frames.
no setteroverride
- isReady → bool
-
Returns when the image is loaded and ready to be used.
no setteroverride
- length → int
-
The number of frames in this provider.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scale → double
-
A scale to render the frames of this provider at.
no setteroverride
Methods
-
getFrame(
int index) → Rect -
Returns the Rect that defines the boundaries of the frame specified by the
index
.override -
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