0 votes

I have a VBoxContainer to which I add Labels in code. I then set the pivot offset of the labels to their centers:

        for i in range(num_selections):
            new_selection = Label.new()
            new_selection.name = "Selection" + str(i)
            new_selection.text = selection_texts[i]
            new_selection.align = Label.ALIGN_CENTER
            new_selection.rect_pivot_offset.x = new_selection.rect_size.x/2
            new_selection.rect_pivot_offset.y = new_selection.rect_size.y/2

Later in code when I scale the Labels the scale behaviour seems to be ignoring the pivot offset and stretching the Label up and to the right.

Is this a consequence of the label being a child of a VBoxContainer? Is there some way to force the label to scale in the way I want?

Godot version v3.3.stable.official
in Engine by (65 points)

1 Answer

0 votes

If your VBoxContainer isn't already a child of something in the scene

 new_selection.rect_pivot_offset.x = new_selection.rect_size.x/2
 new_selection.rect_pivot_offset.y = new_selection.rect_size.y/2

will both be set to 0 and the labels will be stretched down and right by default. If they're being stretched up and right... something strange is going on. Make sure your VBoxContainer is added to a node in the scene before adding your labels to the container and see if that fixes your problem.

Have you used the remote inspector to see what the values of your labels' rect_pivot_offset s are at runtime?

by (3,882 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 Frequently asked questions and 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 [email protected] with your username.