mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
added onCompleteAnimation to trigger when animation finished
This commit is contained in:
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user