Make AnimationPlayer::start and ::play work accordingly to documentation (#14546)

# Objective

While scrolling through the animation crate, I was confused by the docs
and code for the two methods. One does nothing for resetting an
animation, the other just resets the weights for whatever reason.

## Solution

Made the functions work accordingly to their documentation.
`start` now replays the animation.
And `play` doesn't reset the weight anymore. I have no clue why it
should. `play` is there to don't do anything to an already existing
animation.

## Testing

I tested the current 0.14 code with bevy playground in the Animated Fox
exampled and changed it such that on pressing space, either `play` or
`start` would be called. Neither changed anything.
I then inlined the function for start there and it restarted the
animation, so it should work.

---

## Migration Guide

`AnimationPlayer::start` now correspondingly to its docs restarts a
running animation.
`AnimationPlayer::play` doesn't reset the weight anymore.
This commit is contained in:
Lixou 2024-07-31 16:07:53 +02:00 committed by GitHub
parent 68dc7a8b8b
commit 20264d0810
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -564,14 +564,14 @@ thread_local! {
impl AnimationPlayer { impl AnimationPlayer {
/// Start playing an animation, restarting it if necessary. /// Start playing an animation, restarting it if necessary.
pub fn start(&mut self, animation: AnimationNodeIndex) -> &mut ActiveAnimation { pub fn start(&mut self, animation: AnimationNodeIndex) -> &mut ActiveAnimation {
self.active_animations.entry(animation).or_default() let playing_animation = self.active_animations.entry(animation).or_default();
playing_animation.replay();
playing_animation
} }
/// Start playing an animation, unless the requested animation is already playing. /// Start playing an animation, unless the requested animation is already playing.
pub fn play(&mut self, animation: AnimationNodeIndex) -> &mut ActiveAnimation { pub fn play(&mut self, animation: AnimationNodeIndex) -> &mut ActiveAnimation {
let playing_animation = self.active_animations.entry(animation).or_default(); self.active_animations.entry(animation).or_default()
playing_animation.weight = 1.0;
playing_animation
} }
/// Stops playing the given animation, removing it from the list of playing /// Stops playing the given animation, removing it from the list of playing