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: If you are experiencing problems with ghost lines, the less
performant Canvas.drawImageRect can be used instead of Canvas.drawAtlas.
To activate this mode, pass in useAtlas = false
to the constructor or
load method that you are using and each BatchItem will be rendered using
the Canvas.drawImageRect method instead.
Constructors
- SpriteBatch(Image atlas, {RSTransform? defaultTransform, bool useAtlas = true, Color? defaultColor, BlendMode? defaultBlendMode, Images? imageCache, String? imageKey})
Properties
- atlas ↔ Image
-
The atlas used by the SpriteBatch.
getter/setter pair
-
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
- imageCache → Images
-
When the
_imageCache
isn't specified, the global Flame.images is used.no setter - imageKey → String
-
When the
_imageKey
isn't specified imageKey will return either the key for the atlas stored in imageCache or a key generated from the identityHashCode.no setter - isEmpty → bool
-
Does this batch contain any operations?
no setter
- length → int
-
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
- useAtlas → bool
-
Whether to use Canvas.drawAtlas or not.
final
- 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, bool flip = false, Color? color}) → void - Add a new batch item.
-
addTransform(
{required Rect source, RSTransform? transform, bool flip = false, 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 -
replace(
int index, {Rect? source, Color? color, RSTransform? transform}) → void -
Replace provided values of a batch item at the
index
, when a parameter is not provided, the original value of the batch item will be used. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
load(
String path, {RSTransform? defaultTransform, Images? images, Color? defaultColor, BlendMode? defaultBlendMode, bool useAtlas = true}) → Future< SpriteBatch> - Takes a path of an image, and optional arguments for the SpriteBatch.