added onCompleteAnimation to trigger when animation finished

This commit is contained in:
Diego Garcia
2020-04-03 10:42:18 -03:00
parent e19f87046c
commit c1389e2736
2 changed files with 7 additions and 0 deletions

View File

@ -15,6 +15,8 @@ class Frame {
Frame(this.sprite, this.stepTime);
}
typedef OnCompleteAnimation = void Function();
/// Represents an animation, that is, a list of sprites that change with time.
class Animation {
/// The frames that compose this animation.
@ -34,6 +36,9 @@ class Animation {
/// Whether the animation loops after the last sprite of the list, going back to the first, or keeps returning the last when done.
bool loop = true;
/// Registered method to be triggered when the animation complete.
OnCompleteAnimation onCompleteAnimation;
/// Creates an animation given a list of frames.
Animation(this.frames, {this.loop = true});
@ -204,6 +209,7 @@ class Animation {
return;
}
if (!loop && isLastFrame) {
onCompleteAnimation?.call();
return;
}
while (clock > currentFrame.stepTime) {