Tuesday, March 19, 2019

1. Label

We create a Node and attach a script to it.


The script creates a Label node with code, and sets some of its properties, and finally adds it as a child.


We use the screen size, which we set to 200 by 50 in project settings.



extends Node

var lbl = Label.new()
var screen_size

func _ready():
    screen_size = get_viewport().size
    lbl.set_size(screen_size)
    lbl.set_align(Label.ALIGN_CENTER)
    lbl.set_valign(Label.VALIGN_CENTER)
    lbl.set_text("Hello world!")
    add_child(lbl)

The output is a label with the text 'Hello World!':


No comments:

Post a Comment