Add `Animation::is_finished`
@@ -85,7 +85,7 @@ impl Animation {
pub fn advance_by(&mut self, duration: Duration) {
self.timer += duration;
- let frames_remaining = self.current_frame < self.frames.len() - 1;
+ let frames_remaining = self.has_frames_remaining();
if frames_remaining || self.repeating {
while self.timer >= self.frame_length {
@@ -199,4 +199,16 @@ impl Animation {
pub fn set_current_frame_time(&mut self, duration: Duration) {
self.timer = duration;
}
+
+ /// Returns true if this animation will no longer advance.
+ ///
+ /// Will always be false for repeating animations.
+ pub fn is_finished(&self) -> bool {
+ !self.repeating && !self.has_frames_remaining()
+ }
+
+ /// Returns true if there are any frames remaining in the current cycle.
+ pub fn has_frames_remaining(&self) -> bool {
+ self.current_frame < self.frames.len() - 1
+ }
}
