Always call set_animation in set_sprite_frames#86277
Open
rileylyman wants to merge 1 commit into
Open
Conversation
dalexeev
reviewed
Dec 18, 2023
set_animation in set_sprite_framesset_animation in set_sprite_frames
6772b0c to
ed4b82c
Compare
Member
|
The changes look good to me. Please make the same changes to |
ed4b82c to
5ad4df1
Compare
Member
AThousandShips
left a comment
There was a problem hiding this comment.
Cleaner and avoids using index on a list (even though it's equivalent it's better to avoid it)
|
|
||
| animation = StringName(); | ||
| if (!al.is_empty()) { | ||
| set_animation(frames->has_animation(animation) ? animation : al[0]); |
Member
There was a problem hiding this comment.
Suggested change
| set_animation(frames->has_animation(animation) ? animation : al[0]); | |
| set_animation(frames->has_animation(animation) ? animation : *al.front()); |
|
|
||
| animation = StringName(); | ||
| if (!al.is_empty()) { | ||
| set_animation(frames->has_animation(animation) ? animation : al[0]); |
Member
There was a problem hiding this comment.
Suggested change
| set_animation(frames->has_animation(animation) ? animation : al[0]); | |
| set_animation(frames->has_animation(animation) ? animation : al.front()); |
Contributor
Author
There was a problem hiding this comment.
I tried it, it turned out I needed al.front()->get() instead, which I find a lot less clear and the same amount of scary since it requires a ptr deref, so i would prefer to keep al[0]
Member
There was a problem hiding this comment.
You can instead do:
Suggested change
| set_animation(frames->has_animation(animation) ? animation : al[0]); | |
| set_animation(frames->has_animation(animation) ? animation : *al.front()); |
Which should be clearer, but it's either way 🙂
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #86058.
Before this patch, say that an
AnimatedSprite2Dcalledacurrently has the active animation of"foo". If we updatea's sprite frames and the new sprite frames also have an animation called"foo", thenawill not callset_animation("foo")and so will continue to execute the new"foo"animation as if it was the original"foo"animation. It will continue playing from the same frame with the same speed, even if the new"foo"has fewer frames or should last for a different duration.This manifested in #86058 with the
"default"animation. The first frame of the"default"animation in this case was supposed to last for a duration of10, but only lasted for1since we never calledset_animation("default")with the new sprite frames and so theAnimatedSprite2Djust used its default values until the next frame.I also think we could get the engine to error by writing some sort of script that swapped between two sets of sprite frames with the same animation name but different frame lengths, but I didn't try it. This change would fix that as well.