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
Label 组件能在游戏空间中渲染出一些文本. 默认连同 sprite 和瓷砖图一起排序和渲染. 组件的各种属性控制着文本如何被渲染. Defold 的 GUI 也能显示文本但是难以把它放在游戏世界里. Label 可以更容易做到这一点.
要创建一个 Label 组件, 在游戏对象上 右键点击 选择 Add Component ▸ Label.
(如果你希望从一个模板创建多个 label 可以: 在 Assets 浏览器里的文件夹上 右键点击 选择 New... ▸ Label 来创建Label文件, 然后再在任意游戏对象上把它作为组件添加上去)
设置 Font 属性为需要使用的字体还要确定 Material 属性的设置与字体相匹配:
除了 Id, Position, Rotation 和 Scale 外还有一些特有属性:
默认材质出于性能原因关闭了阴影渲染.
Blend Mode 属性定义了可视组件如何与其后面的图像混合. 以下列举了支持的混合模式及其混合算法:
src.a * src.rgb + (1 - src.a) * dst.rgb
src.rgb + dst.rgb
src.rgb * dst.rgb
src.rgb - dst.rgb * dst.rgb
你可以通过设置锚点来改变文本的对齐方式.
Center
, North
或者 South
, 则文本居中对齐.West
模式, 则文本左对齐.East
模式, 则文本右对齐.你可以使用在运行时操控 labels 的文本以及其他一系列的值.
color
vector4
)outline
vector4
)shadow
vector4
)scale
number
用于等比缩放, 要么是 vector3
分轴向缩放.size
vector3
)function init(self)
-- Set the text of the "my_label" component in the same game object
-- as this script.
label.set_text("#my_label", "New text")
end
function init(self)
-- Set the color of the "my_label" component in the same game object
-- as this script. Color is a RGBA value stored in a vector4.
local grey = vmath.vector4(0.5, 0.5, 0.5, 1.0)
go.set("#my_label", "color", grey)
-- ...and remove the outline, by setting its alpha to 0...
go.set("#my_label", "outline.w", 0)
-- ...and scale it x2 along x axis.
local scale_x = go.get("#my_label", "scale.x")
go.set("#my_label", "scale.x", scale_x * 2)
end
在 game.project 文件里有些关于标签的 配置项目.
Did you spot an error or do you have a suggestion? Please let us know on GitHub!
GITHUB