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: delayed animation start when switching to a new animation #67

Merged
merged 4 commits into from Jul 1, 2022

Conversation

edwardvear
Copy link
Contributor

The SpriteSheetAnimationState update function doesn't always update
the sprite index to match the current frame index. When changing
animations, this delays update of sprite.index until after the first
frame duration has elapsed.

To fix this, always update the sprite index to match the current frame.

The `SpriteSheetAnimationState` `update` function doesn't always update
the sprite index to match the current frame index. When changing
animations, this delays update of `sprite.index` until after the first
frame duration has elapsed.

To fix this, always update the sprite index to match the current frame.
@edwardvear edwardvear changed the title Fix delayed animation start when switching to a new animation. fix: Delayed animation start when switching to a new animation. Jun 24, 2022
@edwardvear edwardvear changed the title fix: Delayed animation start when switching to a new animation. fix: delayed animation start when switching to a new animation. Jun 24, 2022
@edwardvear edwardvear changed the title fix: delayed animation start when switching to a new animation. fix: delayed animation start when switching to a new animation Jun 24, 2022
@edwardvear
Copy link
Contributor Author

edwardvear commented Jun 24, 2022

To verify this issue, I printed out the state of my character each frame; whenever the state is updated, I update the Handle<SpriteSheetAnimation> to a matching animation. I local modded benimator to print out the sprite and frame indices at the end of the update function.

State: Idle
Sprite idx: 2, Frame idx: 2
State: Running
Sprite idx: 2, Frame idx: 10
State: Running
Sprite idx: 2, Frame idx: 10
State: Running
Sprite idx: 11, Frame idx: 11

You can see that even though the frame index updates to match the new animation, the sprite index is not updated until the first frame of the new animation completes. This happens regardless of whether the AnimationState is reset when changing animations.

Compared to the behavior with the proposed change:

State: Idle
Sprite idx: 1, Frame idx: 1
State: Idle
Sprite idx: 1, Frame idx: 1
State: Running
Sprite idx: 9, Frame idx: 9
State: Running
Sprite idx: 9, Frame idx: 9

@jcornaz
Copy link
Owner

jcornaz commented Jun 24, 2022

Thank you for the contribution 👍

I'd prefer a unit test, rather that a manual testing procedure. I can write one if you don't know how to or don't have time.

@jcornaz jcornaz self-requested a review June 24, 2022 07:01
@jcornaz jcornaz self-assigned this Jun 24, 2022
@jcornaz jcornaz added the bug Something isn't working label Jun 24, 2022
@edwardvear
Copy link
Contributor Author

I can put together a unit test tomorrow/over the weekend. Thanks for taking a look!

Copy link
Owner

@jcornaz jcornaz left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks 👍

@jcornaz jcornaz enabled auto-merge (squash) July 1, 2022 16:12
@jcornaz jcornaz merged commit 3c025c0 into jcornaz:main Jul 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 2, 2022

🎉 This issue has been resolved in version 3.6.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants