Hi, I'm new to using Godot technology. I'm studying making a prototype and I have a problem regarding the alignment of a Label.

Could anyone help with this question and tell me where I'm going wrong?

Thank you very much for your attention and I'm excited to use Godot.

extends Node2D

var block_texture = preload("res://block.svg") # Substitua pelo caminho da sua textura de bloco
var block_scores = [10, 20, 30, 40, 50, 60] # Pontuação para cada bloco
var block_distance = 50 # Distância entre os blocos

func _ready():
for i in range(block_scores.size()):
var block = Sprite2D.new()
block.texture = block_texture
block.position = Vector2(get_viewport().size.x / 2, get_viewport().size.y - i * (block_texture.get_height() + block_distance))
add_child(block)

	var score_label = Label.new()
	score_label.text = str(block_scores[i])
	score_label.align = Label.ALIGN_CENTER
	score_label.valign = Label.VALIGN_CENTER
	score_label.rect_min_size = block_texture.get_size()
	block.add_child(score_label)
  • Toxe replied to this.

    marcelodelta Could anyone help with this question

    Well, what exactly is the question? I assume you are trying to position a label at the center of your sprite? Setting the align properties won't help here, try setting anchors_preset to center.

    But it would be better if you don't create your sprite + label by code and instead create a new scene that contains your sprite and the label, position and configure them in the 2D view of the editor and then instantiate this scene.

    Thank you very much for your attention.

    I imagined it would all be via code. I will work in the format you suggested, to try.

    Thanks.