【问题标题】:Godot how to center text on label?Godot如何在标签上居中文本?
【发布时间】:2019-02-14 05:06:28
【问题描述】:

我刚刚创建了一个新的 Godot 项目并创建了一个带有文本的标签。即使使用 Align: center 在我运行游戏时文本仍保持在左上角。

标签.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" ]

【问题讨论】:

  • 请发布您的 .tscn 文件(只是场景的minimal 版本)。
  • 好吧,我添加了它编辑:好的,我刚刚添加了 100 的左边距和上边距,并且能够移动文本哈哈仍然没有居中,但是嗯

标签: user-interface godot


【解决方案1】:

将 Align 和 Valign 设置为 Center 后,您必须同时调整锚点和边距。你有一些不同的选择来做到这一点。

  • 在布局中选择“中心”将通过将锚点调整为 0.5(屏幕中心)使标签居中,并计算边距,以便 Rect 居中(不改变其大小)。

  • 在 Layout 中选择“Full Rect”会将锚点设置为(0,0,1,1,即全屏),边距设置为 0,并且会更改 Label 节点的 Rect,以便节点将填满屏幕。

当您选择控制节点(标签、容器等)时,工具栏中会出现布局按钮。 screenshot to show Layout button in Godot 3

Obs.:最好先创建一个 Container 节点,将 Container 节点设置为 Full Rect,然后为您的标签创建子节点。您的锚点设置在父级的 Rect 内。

【解决方案2】:

只需将AlignValign 属性设置为Center 即可使文本居中。必须缩放标签的边界矩形才能实际看到效果。您可以通过在 2D 视图中拖动矩形的控制点或在检查器的“控制”部分中更改矩形的“边距”或“大小”来做到这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-15
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 2011-03-03
    • 1970-01-01
    • 2016-04-02
    • 2015-10-18
    相关资源
    最近更新 更多