Wednesday, March 20, 2019

8. Button

A Button node is used in this example. We monitor two of the signals that a button can emit, for the down (pressed) and up (released) case.


Depending on which signal is emitted, we set the label to two different strings indicating the state.


We use the following nodes:



In the top-most node, Control, we attach this script:



extends Control

var label
var button

func _ready():
    button = get_node("Button")
    button.connect("button_up",self,"_on_Button_button_up")
    button.connect("button_down",self,"_on_Button_button_down")
    label = get_node("Label")
    button.set_text("Press Me")

func _on_Button_button_down():
    label.set_text("Button is down")

func _on_Button_button_up():
    label.set_text("Button is up")

The output, with window size of 200,200, when the button is pressed showing the button darkened and text indicating the state:


No comments:

Post a Comment