mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-04 04:47:13 +08:00
added onCompleteAnimation to trigger when animation finished
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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