playOnce method
Future
playOnce(
- FutureOr<
SpriteAnimation> animation, { - VoidCallback? onFinish,
- VoidCallback? onStart,
- bool runToTheEnd = false,
- bool flipX = false,
- bool flipY = false,
- bool useCompFlip = false,
- Vector2? size,
- Vector2? offset,
Method used to play animation once time
Implementation
Future playOnce(
FutureOr<SpriteAnimation> animation, {
VoidCallback? onFinish,
VoidCallback? onStart,
bool runToTheEnd = false,
bool flipX = false,
bool flipY = false,
bool useCompFlip = false,
Vector2? size,
Vector2? offset,
}) async {
_fastAnimationOffset = offset ?? Vector2.zero();
runToTheEndFastAnimation = runToTheEnd;
bool lastFlipX = isFlipHorizontally;
bool lastFlipY = isFlipVertically;
_fastAnimation?.onRemove();
_fastAnimation = AnimatedObjectOnce(
position: position + _fastAnimationOffset,
size: size ?? this.size,
animation: animation,
onStart: onStart,
onFinish: () {
onFinish?.call();
_fastAnimation?.onRemove();
_fastAnimation = null;
if (!useCompFlip) {
isFlipHorizontally = lastFlipX;
isFlipVertically = lastFlipY;
}
},
);
if (!useCompFlip) {
isFlipVertically = flipY;
isFlipHorizontally = flipX;
}
if (gameRef != null) {
_fastAnimation?.gameRef = gameRef!;
}
await _fastAnimation?.onLoad();
}