Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elapsed time to Animation #23

Merged
merged 1 commit into from
Oct 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Animation {
/// It's ticked by the update method. It's reset every frame change.
double clock = 0.0;

/// Total elapsed time of this animation, in seconds, since start or a reset.
double elapsed = 0.0;

/// Wether 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;

Expand Down Expand Up @@ -120,6 +123,7 @@ class Animation {
/// Resets the animation, like it'd just been created.
void reset() {
this.clock = 0.0;
this.elapsed = 0.0;
this.currentIndex = 0;
}

Expand All @@ -141,6 +145,7 @@ class Animation {
/// Updates this animation, ticking the lifeTime by an amount [dt] (in seconds).
void update(double dt) {
clock += dt;
elapsed += dt;
if (!loop && isLastFrame) {
return;
}
Expand Down