Skip to content

Commit f6b03aa

Browse files
committed
Rename play to start and add new play method that won't overwrite 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.
1 parent b291223 commit f6b03aa

File tree

1 file changed

+9
-1
lines changed
  • crates/bevy_animation/src

1 file changed

+9
-1
lines changed

crates/bevy_animation/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,22 @@ impl Default for AnimationPlayer {
115115

116116
impl AnimationPlayer {
117117
/// Start playing an animation, resetting state of the player
118-
pub fn play(&mut self, handle: Handle<AnimationClip>) -> &mut Self {
118+
pub fn start(&mut self, handle: Handle<AnimationClip>) -> &mut Self {
119119
*self = Self {
120120
animation_clip: handle,
121121
..Default::default()
122122
};
123123
self
124124
}
125125

126+
/// Start playing an animation, resetting state of the player, unless the requested animation is already playing.
127+
pub fn play(&mut self, handle: Handle<AnimationClip>) -> &mut Self {
128+
if self.animation_clip != handle || self.is_paused() {
129+
self.start(handle);
130+
}
131+
self
132+
}
133+
126134
/// Set the animation to repeat
127135
pub fn repeat(&mut self) -> &mut Self {
128136
self.repeat = true;

0 commit comments

Comments
 (0)