Skip to content

Commit

Permalink
Rename play to start and add new play method that won't overwri…
Browse files Browse the repository at this point in the history
…te the existing animation if it's already playing (#6350)

# Objective

- You usually want to say that a given animation *should* be playing, doing nothing if it's already playing.

## Solution

- Rename play to start and add new play method that won't overwrite the existing animation if it's already playing #6350

---

## Changelog

### Changed

`AnimationPlayer::play` will now not restart the animation if it's already playing

### Added

An `AnimationPlayer ::start` method, which has the old behavior of `play`

## Migration guide

- If you were using `play` to restart an animation that was already playing, that functionality has been moved to `start`. Now, `play` won't have any effect if the requested animation is already playing.
  • Loading branch information
anchpop committed Oct 24, 2022
1 parent b291223 commit f6b03aa
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/bevy_animation/src/lib.rs
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 f6b03aa

Please sign in to comment.