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 24, 2022
1 parent 7989cb2 commit 924544e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,22 @@ impl Default for AnimationPlayer {

impl AnimationPlayer {
/// Start playing an animation, resetting state of the player
pub fn play(&mut self, handle: Handle<AnimationClip>) -> &mut Self {
pub fn start(&mut self, handle: Handle<AnimationClip>) -> &mut Self {
*self = Self {
animation_clip: handle,
..Default::default()
};
self
}

/// Start playing an animation, resetting state of the player, unless the requested animation is already playing.
pub fn play(&mut self, handle: Handle<AnimationClip>) -> &mut Self {
if self.animation_clip != handle || self.is_paused() {
self.start(handle);
}
self
}

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

0 comments on commit 924544e

Please sign in to comment.