render method
void
render(})
Renders this sprite onto the canvas
.
position
: x,y coordinates where it will be drawn; default to origin.size
: width/height dimensions; it can be bigger or smaller than the original size -- but it defaults to the original texture size.anchor
: where in the sprite the x/y coordinates refer to; defaults to topLeft.overridePaint
: paint to use. You can also change the paint on your Sprite instance. Default is white.
Implementation
void render(
Canvas canvas, {
Vector2? position,
Vector2? size,
Anchor anchor = Anchor.topLeft,
Paint? overridePaint,
}) {
final drawPosition = position ?? Vector2.zero();
final drawSize = size ?? srcSize;
final delta = anchor.toVector2()..multiply(drawSize);
final drawRect = (drawPosition + delta).toPositionedRect(drawSize);
final drawPaint = overridePaint ?? paint;
canvas.drawImageRect(image, src, drawRect, drawPaint);
}