SpriteBatch class
The SpriteBatch API allows for rendering multiple items at once.
This class allows for optimization when you want to draw many parts of an image onto the canvas. It is more efficient than using multiple calls to Canvas.drawImageRect and provides more functionality by allowing each BatchItem to have their own transform rotation and color.
By collecting all the necessary transforms on a single image and sending those transforms in a single batch to the GPU, we can render multiple parts of a single image at once.
Note: Currently web does not support Canvas.drawAtlas
, which SpriteBatch uses under
the hood, instead it will render each BatchItem using Canvas.drawImageRect
, so there
might be a performance hit on web when working with many batch items.
Constructors
- SpriteBatch(Image atlas, {Color defaultColor = const Color(0x00000000), BlendMode defaultBlendMode = BlendMode.srcOver, RSTransform? defaultTransform})
Properties
- atlas → Image
-
The atlas used by the SpriteBatch.
final
-
colors
→ UnmodifiableListView<
Color> -
The colors list shouldn't be modified directly, that is why an
UnmodifiableListView is used. If you want to add colors use the
add or addTransform method.
no setter
- defaultBlendMode → BlendMode
-
The default blend mode, used for blending a batch item.
final
- defaultColor → Color
-
The default color, used as a background color for a BatchItem.
final
- defaultTransform → RSTransform?
-
The default transform, used when a transform was not supplied for a BatchItem.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → int
-
The height of the atlas.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → Vector2
-
The size of the atlas.
no setter
-
sources
→ UnmodifiableListView<
Rect> -
The sources list shouldn't be modified directly, that is why an
UnmodifiableListView is used. If you want to add sources use the
add or addTransform method.
no setter
-
transforms
→ UnmodifiableListView<
RSTransform> -
The transforms list shouldn't be modified directly, that is why an
UnmodifiableListView is used. If you want to add transforms use the
add or addTransform method.
no setter
- width → int
-
The width of the atlas.
no setter
Methods
-
add(
{required Rect source, double scale = 1.0, Vector2? anchor, double rotation = 0, Vector2? offset, Color? color}) → void - Add a new batch item.
-
addTransform(
{required Rect source, RSTransform? transform, Color? color}) → void - Add a new batch item using a RSTransform.
-
clear(
) → void - Clear the SpriteBatch so it can be reused.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
render(
Canvas canvas, {BlendMode? blendMode, Rect? cullRect, Paint? paint}) → void -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
load(
String path, {Color defaultColor = const Color(0x00000000), BlendMode defaultBlendMode = BlendMode.srcOver, RSTransform? defaultTransform, Images? images}) → Future< SpriteBatch> - Takes a path of an image, and optional arguments for the SpriteBatch.