drawImage method

void drawImage(
  1. Images frames, [
  2. int frame = 0,
  3. double x = 0.0,
  4. double y = 0.0,
  5. double rotation = 0.0,
  6. double scaleX = 1.0,
  7. double scaleY = 1.0,
  8. ColorList? colors,
])

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 (frames.isLoading) {
    return;
  }

  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();
}