Manuals
Manuals




This translation is community contributed and may not be up to date. We only maintain the English version of the documentation. Read this manual in English

GUI文本节点

Defold支持一种特定类型的GUI节点,允许在GUI场景中渲染文本。项目中添加的任何字体资源都可以用于文本节点渲染。

添加文本节点

您希望在GUI文本节点中使用的字体必须添加到GUI组件中。可以右键单击Fonts文件夹,使用GUI顶部菜单或按相应的键盘快捷键。

Fonts

文本节点具有一组特殊属性:

Font
您创建的任何文本节点都必须设置Font属性。
Text
此属性包含显示的文本。
Line Break
文本对齐遵循 pivot 设置,设置此属性允许文本流到多行。节点的宽度决定文本将在何处换行。

对齐

通过设置节点 pivot,您可以更改文本的对齐模式。

Center
如果 pivot 设置为CenterNorthSouth,则文本居中对齐。
Left
如果 pivot 设置为任何West模式,则文本左对齐。
Right
如果 pivot 设置为任何East模式,则文本右对齐。

文本对齐

运行时修改文本节点

文本节点响应任何通用的节点操作函数,用于设置大小、pivot、颜色等。存在一些仅用于文本节点的函数:

function on_message(self, message_id, message, sender)
    if message_id == hash("set_score") then
        local s = gui.get_node("score")
        gui.set_text(s, message.score)
    end
end