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,
double? bleed,
}) {
if (position != null) {
_tmpRenderPosition.setFrom(position);
} else {
_tmpRenderPosition.setZero();
}
_tmpRenderSize.setFrom(size ?? srcSize);
_tmpRenderPosition.setValues(
_tmpRenderPosition.x - (anchor.x * _tmpRenderSize.x),
_tmpRenderPosition.y - (anchor.y * _tmpRenderSize.y),
);
if (bleed != null) {
_tmpRenderPosition.x -= bleed;
_tmpRenderPosition.y -= bleed;
_tmpRenderSize.x += bleed * 2;
_tmpRenderSize.y += bleed * 2;
}
final drawRect = _tmpRenderPosition.toPositionedRect(_tmpRenderSize);
final drawPaint = overridePaint ?? paint;
canvas.drawImageRect(image, src, drawRect, drawPaint);
}