9

I just made a new Godot project and created a Label with text. Even with Align: center the text stays top left when I run the game.

Label.tscn

[gd_scene format=2]

[node name="Label" type="Label" index="0"]

anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 40.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "heylab"
align = 1
valign = 1
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Anchor" ]
shwick
  • 4,277
  • 6
  • 21
  • 28
  • Please post your .tscn file (just a [minimal](https://stackoverflow.com/help/mcve) version of the scene). – skrx Sep 09 '18 at 16:33
  • alright I added it edit: ok I just added a Left and Top margin of 100 and was able to move the text haha still not centered but meh – shwick Sep 09 '18 at 17:21

2 Answers2

6

After setting Align and Valign to Center, you have to adjust both anchors and margins. You have some different options to do that.

  • Choosing "Center" in Layout will center your label by adjusting anchors to 0.5 (center of screen), and will calculate Margins, so that the Rect will be centered (without changing its size).

  • Choosing "Full Rect" in Layout will set anchor to (0, 0, 1, 1, that is the full screen), margins to 0, and will change the Rect of your Label node, so that the node will fill the screen.

The Layout button appears in the toolbar when you select Control nodes (Labels, Containers etc). screenshot to show Layout button in Godot 3

Obs.: It's probably better to first create a Container node, set Container node to Full Rect, then create child nodes for your label. Your anchors are set inside the parent's Rect.

Gustavo Kaneto
  • 643
  • 7
  • 17
  • You can learn more about it here: http://docs.godotengine.org/en/3.0/tutorials/gui/size_and_anchors.html and here: http://docs.godotengine.org/en/3.0/getting_started/step_by_step/ui_main_menu.html – Gustavo Kaneto Sep 11 '18 at 00:32
4

Just set the Align and Valign properties to Center to center the text. The bounding rect of the label has to be scaled to actually see the effect. You can do that by dragging the control points of the rect in the 2D view or change the "Margin" or "Size" of the rect in the "Control" section of the inspector.

skrx
  • 19,980
  • 5
  • 34
  • 48