0 votes

hey i want to build a character selection ui so i created a button and link it to a texture rect node when pressed it load another character but i don't know how to make it go back to the original character

My code:
func onnextcharacterButton_pressed():
$TextureRect2/TextureRect2/AnimatedSprite.animation = "historian"

asked Mar 16 in Projects by blink (12 points)

1 Answer

0 votes

It looks like you're just assigning a specific, named animation when the button is pressed. Depending on your needs, you could store your various animation names in an array and present them from there.

You could store your current array index in a variable and each time you press the button, you could increment your array index variable and load the animation stored at that index. Once the last animation is loaded, another button press could load the first one again.

You could easily expand on that by providing 2 buttons, one to move forward through the animation array and one to move backwards.

answered Mar 17 by jgodfrey (5,246 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.