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"

in Engine by (20 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.

by (10,928 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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.