drawImage method
Draws a specific frame from an Images sequence (sprite sheet or animation).
frames: The Images object containing the frame(s) to draw.frame: The index of the frame to draw. Defaults to 0.x,y: The position to draw the image at (considers image's pivot). Defaults to (0,0).rotation: Rotation angle in degrees. Defaults to 0.0.scaleX,scaleY: Scaling factors. Defaults to 1.0.colors: An optional ColorList for tinting the image.colors[0]is used.
If the frames are still loading this method does nothing.
Implementation
void drawImage(
Images frames, [
int frame = 0,
double x = 0.0,
double y = 0.0,
double rotation = 0.0,
double scaleX = 1.0,
double scaleY = 1.0,
ColorList? colors,
]) {
if (frame < 0 || frame >= frames.length) {
die("Image has ${frames.length} frames, you requested frame: $frame");
}
var image = frames[frame];
pushMatrix();
translate(x, y);
scale(scaleX, scaleY);
rotate(rotation);
translate(-image.pivotX * image.width, -image.pivotY * image.height);
drawTexture(
image.texture,
srcX: image.sourceRect.x.toDouble(),
srcY: image.sourceRect.y.toDouble(),
srcWidth: image.width.toDouble(),
srcHeight: image.height.toDouble(),
x: 0,
y: 0,
width: image.width.toDouble(),
height: image.height.toDouble(),
colors: colors,
);
popMatrix();
}