add method
void
add({})
Add a new batch item.
The source
parameter is the source location on the atlas. You can
position it on the canvas using the offset
parameter.
You can transform the sprite from its offset
using scale
, rotation
,
anchor
and flip
.
The color
parameter allows you to render a color behind the batch item,
as a background color.
This method creates a new RSTransform based on the given transform arguments. If many RSTransform objects are being created and there is a way to factor out the computations of the sine and cosine of the rotation (which are computed each time this method is called) and reuse them over multiple RSTransform objects, it may be more efficient to directly use the more direct addTransform method instead.
Implementation
void add({
required Rect source,
double scale = 1.0,
Vector2? anchor,
double rotation = 0,
Vector2? offset,
bool flip = false,
Color? color,
}) {
anchor ??= Vector2.zero();
offset ??= Vector2.zero();
RSTransform? transform;
// If any of the transform arguments is different from the defaults,
// then we create one. This is to prevent unnecessary computations
// of the sine and cosine of the rotation.
if (scale != 1.0 ||
anchor != Vector2.zero() ||
rotation != 0 ||
offset != Vector2.zero()) {
transform = RSTransform.fromComponents(
scale: scale,
anchorX: anchor.x,
anchorY: anchor.y,
rotation: rotation,
translateX: offset.x,
translateY: offset.y,
);
}
addTransform(
source: source,
transform: transform,
flip: flip,
color: color,
);
}