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.
This commit is contained in:
parent
b291223e34
commit
f6b03aa27c
@ -115,7 +115,7 @@ 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()
|
||||
@ -123,6 +123,14 @@ impl AnimationPlayer {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user