What is the issue you are having with the AnimatedSprite? Is it not playing correctly or at the right times?
If you are using an AnimatedSprite, then you will want to make sure it's on top of the TextureButton node and that it has the animations setup. Then calling play
like in the code you have should work, as long as the functions/signals are setup correctly and the animation name you are passing to the play
function is a name of one of the animations in the AnimatedSprite.
Looking at the code above, as long as you have animations called default 1
and New Anim
on your AnimatedSprite, have the AnimatedSprite as a child of the TextureButton node, and have the mouse entered and mouse exited signals setup, I think the code should work.
Looking at the code, it looks like you are trying to animate a button, correct? If so, you may want to use a Control-based node for the animation so it can scale with the UI. It's not required by any means, but Node2D nodes don't have some of the anchoring and layout settings that make it scale nicely with different sized displays.
That said though, if your UI doesn't resize and/or you have the scale mode set to 2d
, then using an AnimatedSprite is probably fine since the resizing should be handled by Godot.
However, if you're not using a scale mode of 2d
and/or you want to better support resizing UI, You may want to use a TextureRect node and then animate it with an AnimationPlayer. To change the frames of the animation, you can keyframe the texture
property of the TextureRect. Then instead of calling $AnimatedSprite.play("animation_name")
you would instead call $AnimationPlayer.play("animation_name")
to play the animations stored in the AnimationPlayer node.
Also, I formatted the code in the OP. You can add three ~
enclosing to code or indent everything by a tab to render it as code :smile: