Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AnimatedSprite2D/3D::play using wrong end_frame when playing backwards #93548

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Fix AnimatedSprite2D/3D::play using wrong end_frame when playing backwards #93548

merged 1 commit into from
Jun 26, 2024

Conversation

Robocraft999
Copy link
Contributor

On playing a different animation to the current backwards, will start the new animation on the last animations last frame not the new ones.

For example I have an idle animation with 2 frames. When I now play my activation animation backwards, which has 17 frames, it will start on frame 1 and then go down to 0 (because it's backwards), because the idle animation has only 2 frames. I got it working, if i set the animation beforehand but this feels not right:

portal.set_animation("activation")
portal.play_backwards("activation")

@Robocraft999 Robocraft999 requested a review from a team as a code owner June 24, 2024 12:37
@AThousandShips AThousandShips added bug topic:animation cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Jun 24, 2024
@AThousandShips AThousandShips added this to the 4.3 milestone Jun 24, 2024
@AThousandShips AThousandShips requested a review from a team June 24, 2024 12:39
@Robocraft999
Copy link
Contributor Author

Just seeing this also applies to the AnimatedSprite3D btw.

@Mickeon
Copy link
Contributor

Mickeon commented Jun 24, 2024

The static check fails because there may be extra tab characters on the new line that you need to strip.

Just seeing this also applies to the AnimatedSprite3D btw.

Indeed, you should duplicate this fix on AnimatedSprite3D as well.

Mentioning @dalexeev because they have seen animated sprite's code extensively in the past.

@Robocraft999
Copy link
Contributor Author

should i add the 3D version right here or do another pull request? If so I would rename the pr, commit the change and you have to change the pr tags

@AThousandShips
Copy link
Member

Do it in this and make a single commit with an appropriate title

@Robocraft999 Robocraft999 requested a review from a team as a code owner June 25, 2024 14:25
@AThousandShips AThousandShips changed the title Fixed AnimationSprite2D::play using wrong end_frame Fix AnimationSprite2D/3D::play using wrong end_frame Jun 25, 2024
@AThousandShips
Copy link
Member

AThousandShips commented Jun 25, 2024

Meant to make a single comment of the entire PR please squash your commits into one, see here

And please make the name match the name of the PR

@AThousandShips AThousandShips changed the title Fix AnimationSprite2D/3D::play using wrong end_frame Fix AnimatedSprite2D/3D::play using wrong end_frame Jun 25, 2024
@Robocraft999
Copy link
Contributor Author

like this? Sorry I'm still a bit inexperienced with git

@AThousandShips
Copy link
Member

That's just right

@@ -476,6 +476,8 @@ void AnimatedSprite2D::play(const StringName &p_name, float p_custom_scale, bool
int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is correct as is, but I think it makes sense to move this line to the else block below (so MAX(0, frames->get_frame_count(animation) - 1) would not be done twice when name != animation).

(same for 3d)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but you would still need one for the else branch, but you're right in that it would not be called twice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what was suggested, to move the one that's outside the if to the else

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm suggesting to have separate variables within both if/else blocks (with single assignment each).

On playing a different animation to the current backwards will start the new animation on the last animations last frame not the new ones
@akien-mga akien-mga merged commit cafe704 into godotengine:master Jun 26, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@akien-mga akien-mga changed the title Fix AnimatedSprite2D/3D::play using wrong end_frame Fix AnimatedSprite2D/3D::play using wrong end_frame Jul 9, 2024
@akien-mga akien-mga changed the title Fix AnimatedSprite2D/3D::play using wrong end_frame Fix AnimatedSprite2D/3D::play using wrong end_frame when playing backwards Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release topic:animation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants