Skip to content

Commit

Permalink
fix: impossiblity to restart an animation ran with 'Once' mode (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedodd committed Jul 26, 2021
1 parent 34d6a83 commit 4c7b5ad
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/state.rs
Expand Up @@ -45,6 +45,8 @@ impl SpriteSheetAnimationState {
} else if matches!(animation.mode, AnimationMode::Repeat) {
self.current_frame = 0;
} else {
self.current_frame = 0;
self.elapsed_in_frame = Duration::ZERO;
return true;
}

Expand Down Expand Up @@ -370,6 +372,19 @@ mod tests {
) {
assert!(state.update(&mut sprite_at_second_frame, &animation, frame_duration))
}

#[rstest]
fn returns_to_initial_state(
mut state: SpriteSheetAnimationState,
mut sprite_at_second_frame: TextureAtlasSprite,
animation: SpriteSheetAnimation,
frame_duration: Duration,
) {
state.update(&mut sprite_at_second_frame, &animation, frame_duration);
let expected_state = SpriteSheetAnimationState::default();
assert_eq!(state.current_frame, expected_state.current_frame);
assert_eq!(state.elapsed_in_frame, expected_state.elapsed_in_frame);
}
}
}
}

0 comments on commit 4c7b5ad

Please sign in to comment.