0 votes

So I want to make a character select screen where literally all that happens is that a sprite of a character gets swapped with a different texture once you hit a button on the character select screen, I have tried messing around with button nodes to no avail. I could not find a tutorial on how to make a 2D character select screen. If someone can help me by giving me the basic logic of and some code that can help make a 2D character select screen, then I would be most thankful. Or you can share a tutorial on how to make a 2D character select screen with me, that works just as well. To explain what I want, I want to press the tab key that brings up a menu that contains buttons, and once you click on those buttons the texture on my sprite gets swapped with a different texture. I have gotten the menu to work, but once you click on a character button, it does nothing and it kinda just crashes the game. So I would like to start off with fresh code and not share my code and add on to it as it seems to be causing issues.

Godot version 3.3
in Engine by (39 points)

1 Answer

+1 vote

I don't know of how to create the whole scene but here is how to change the texture.

var texture = load("res://path/to/your/texture.png")
$Sprite.texture = texture
by (2,017 points)

I did that but I now keep getting the error "Invalid set index 'texture' (on base: 'null instance') with value of type 'StreamTexture'." Here is what the code looks like(also the code under the func value is indented, its just I couldn't do that on phone):

extends Button

export(String, FILE) var next_scene_path = ""

func _on_Button_button_up() -> void:
var texture = load(res://Assets/SPACE FOX.png")
$Sprite.texture = texture

func _get_configuration_warning() -> String:
return "next_scene_path must be set for the button to work" if next_scene_path == "" else ""

Are you sure you have the Sprite in your scene and it's name is Sprite?

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 Frequently asked questions and 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 [email protected] with your username.