Added toImage method (#661)

This commit is contained in:
Jochum van der Ploeg
2021-02-23 00:34:21 +01:00
committed by GitHub
parent 4e5b75eafb
commit ec09ce0ce6
4 changed files with 20 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import 'dart:ui';
import '../image_composition.dart';
import 'anchor.dart';
import 'extensions/offset.dart';
import 'extensions/vector2.dart';
@@ -76,4 +77,13 @@ class Sprite {
canvas.drawImageRect(image, src, drawRect, drawPaint);
}
/// Return a new Image based on the [src] of the Sprite.
///
/// **Note:** This is a heavy async operation and should not be called on each [Game.render].
Future<Image> toImage() async {
final composition = ImageComposition()
..add(image, Vector2.zero(), source: src);
return composition.compose();
}
}