render method

void render(
  1. Canvas canvas,
  2. Vector2 position,
  3. double rotation,
  4. double scale,
  5. ScalingMode scalingMode,
  6. Vector2? size,
  7. Paint paint,
)

Implementation

void render(Canvas canvas, Vector2 position, double rotation, double scale, ScalingMode scalingMode, Vector2? size, Paint paint) {
  size = size ?? this.size;

  size = computeRenderSize(scalingMode, size);

  final scaleX = trimSize.x / this.size.x;
  final scaleY = trimSize.y / this.size.y;

  final offsetX = trimOffset.x * (size.x / this.size.x) * scale;
  final offsetY = trimOffset.y * (size.y / this.size.y) * scale;

  canvas.save();

  canvas.translate(position.x, position.y);
  canvas.rotate(rotation);
  canvas.translate(-size.x * scale / 2.0, -size.y * scale / 2.0);

  canvas.drawImageRect(
    image,
    Rect.fromLTWH(this.position.x, this.position.y, this.trimSize.x, this.trimSize.y),
    Rect.fromLTWH(offsetX, offsetY, scaleX * size.x * scale, scaleY * size.y * scale),
    paint,
  );

  canvas.restore();
}