diff --git a/CHANGELOG.md b/CHANGELOG.md index f8584ecce..0f5a61c19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Adding Component#onDestroy - Adding Keyboard events API - Adding Box2DGame, an extension of BaseGame to simplify lifecycle of Box2D components +- Add onAnimateComplete for Animation (thanks @diegomgarcia) ## 0.18.2 - Add loop for AnimationComponent.sequenced() (thanks @wenxiangjiang) diff --git a/lib/animation.dart b/lib/animation.dart index 3a5c5e3be..463e1e113 100644 --- a/lib/animation.dart +++ b/lib/animation.dart @@ -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) {