Skip to content

Commit

Permalink
Add play_unless_already_playing method to AnimationPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop committed Oct 23, 2022
1 parent 7989cb2 commit 249734a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ impl AnimationPlayer {
self
}

/// Like `play`, but does nothing if the requested animation is already playing.
pub fn play_unless_already_playing(&mut self, handle: Handle<AnimationClip>) -> &mut Self {
if self.animation_clip != handle || self.is_paused() {
*self = Self {
animation_clip: handle,
..Default::default()
};
}
self
}

/// Set the animation to repeat
pub fn repeat(&mut self) -> &mut Self {
self.repeat = true;
Expand Down

0 comments on commit 249734a

Please sign in to comment.