How to make a button in Godot

In our earlier tutorial we learned how to move an object in Godot. In this tutorial, we will create a button to increase the speed of the object.

What you will learn

  • Creating a new button.
  • Adding text to the button
  • Linking the button to the object script.

Let’s get started

Creating a new Button

  1. Click on the + sign in the scene window.
  2. Seach for the button node.
  3. Click create to add a button to the scene.
create new node window in Godot

Changing Button properties

  1. Select the button node and go to the inspector window.
  2. You can enter the text that you want to see on the button in the text field.
  3. If you have a design ready for the button you can add it to the icon.
  4. In the Rect properties you can change the size and position of the button.

Linking the button press action to script

  1. Select the button node.
  2. Go to node window near the inspector.
  3. You should see many signals. Double click on the pressed () signal in the BaseButton category.
  4. This will open a window. Select the node you want to link with the button. The node should have a script attached to it. You can change the function name to your liking in the Receiver Method dialog box.
  5. This will create a new function in the script.
  6. Add your required script. In our case it’s a simple line.
func _on_Button_pressed():
	speed+=10

Now play the game and click on the button to increase the player speed by 10. If you have any questions, leave it in the comment section below.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.