mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-13 11:20:19 +08:00
Added toImage method (#661)
This commit is contained in:
committed by
GitHub
parent
4e5b75eafb
commit
ec09ce0ce6
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user