How to Trigger Functions While Previewing AnimatedSprite2D Animations

Godot Version

4.4.1

Question

I am currently developing a 2D Metroidvania game.
In this project, I would like to trigger certain functions—such as controlling the velocity of a CharacterBody2D or enabling hit detection during attacks—at specific keyframes of an AnimatedSprite2D. Ideally, I want to configure these events while visually checking the animation state.

I understand that AnimationPlayer might be useful, but I am confused about how to connect it with AnimatedSprite2D. Since I cannot directly view or manage AnimatedSprite2D animations through AnimationPlayer, I am not sure what the best workflow is.

What would be the best way to set up and adjust these actions while being able to see the animation in progress?

Any advice would be greatly appreciated. Thank you!

I find that the best way to handle it is to NOT use AnimatedSprite2D, but instead, use a normal Sprite2D, and using the AnimationPlayer, directly manipulate the Sprite2D and change it’s frame as the animation plays. This way you can fine control how the animation is played, and you can super easily call any functions or play any sound at any point in the animation.

Just be sure to set the “Texture”, “HFrames” and “VFrames” at the beginning of each new animation.

1 Like

Thanks! This really helped me.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.