0 votes

Hi all.

In a game I'm putting together, I'd like to make some custom buttons. I think TextureButton is the right node, but I don't know how to use it for buttons with a single, custom texture. The code below is for the GUI, aptly called HUD.gd.

extends CanvasLayer

signal play_game

func show_message(text):
    $SystemMessage.text = text
    $SystemMessage.show()
    $MessageDuration.start()

func player_loss():
    show_message("Game Over")
    yield($MessageDuration, "timeout")
    $Button.show()
    $SystemMessage.text = "New Game?"
    $SystemMessage.show()


func score_count(score):
    $TimeSurvived.text = str(score)

func _on_MessageDuration_timeout():
    $SystemMessage.hide()


func _on_Button_pressed():
    $Button.hide()
    emit_signal('play_game')

I'd like to be able to make my own buttons, and know where they'd go in my current project.

in Engine by (197 points)

I know how to use the signals, so I can connect those to what they're going to move. Just working out how to best have the buttons...

1 Answer

0 votes

If you create a button node (as you wrote - TextureButton), you may select in properties your own set of Textures. But if you wish to prepare something like your own styled button - create and set your own Theme. You may also always play with Material and create your own shader. Everything depends on this what you wish to create exactly.
Theme or Shader you may always save as a file and use on another button, that you create.

by (164 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.