Skip to content

Commit

Permalink
Add Animation::is_finished (#315)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Clay <27cupsofcoffee@gmail.com>
  • Loading branch information
vrmiguel and 17cupsofcoffee authored Sep 3, 2022
1 parent d9b6c12 commit 5ef32af
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/graphics/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

0 comments on commit 5ef32af

Please sign in to comment.