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" ]
For Control nodes, you can set their anchors to be centered (choose Layout -> Center) in the menu, or make them a child of a CenterContainer (if you need a dynamic layout for different sized screens).
Add class . text-center to the parent div to align text or any item inside to the center. You can also decide how the alignment should look like on the specific screen sizes.
1 Answer. There are two ways: Add a CanvasLayer to the player then move the Label under it. Move the Label outside of the player.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With