How do I make it so that if I click a button it will change my 2d player sprite into a different image

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ItzLightnin

Hi! I am new to coding and everything and I am currently making a GoDot 2D game, Its mostly mazes but I have a character select in where I want to make it so that If I click a button it will CHANGE my player sprite to that image for other scenes aka the other lvls

you could decouple your player node to your scene levels.

Rather than:

Root

Level01(Node2D)

Player(KinematicBody2D)

You could have a game manager that manages the state of your player outside of the levels.

Root

GameManager(Node)

Level01(Node2D)

Player(KinematicBody2D)

Then your game manager handles spawning your scenes/levels and your player, and other entities.

Although of course, you could have a Global singleton that will hold information of your player sprite.

see: Singletons (Autoload) — Godot Engine (stable) documentation in English

bloodsign | 2021-03-04 19:46

You can also use the AnimatedSprite node in which you can define different animations with different sprites.

Then you’ll only need to call the play function on your animated sprite with the name of your sprite/animation you want to use.

Szesan | 2021-03-05 00:38

:bust_in_silhouette: Reply From: Mrpaolosarino

Like Szesan said, use Animated Sprite and then if you input a button, change it’s frame to whatever you like