概要
属性
API 参考
属性
Font
代码示例
显示所有字体
local frame = script.Parent
-- 创建一个显示每种字体的 TextLabel
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- 设置文本属性
textLabel.Text = font.Name
textLabel.Font = font
-- 一些渲染属性
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- 将框架的大小设为文本的高度
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- 添加到父框架
textLabel.Parent = frame
end
-- 将框架按列表布局(如果它们还没有)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
endFontSize
Text
代码示例
渐隐横幅
local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"欢迎来到我的游戏!",
"确保玩得开心!",
"请给出建议!",
"要对其他玩家友好!",
"不要骚扰其他玩家!",
"查看商店!",
"提示:不要死亡!",
}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local RNG = Random.new()
local fadeIn = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 0,
})
local fadeOut = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 1,
})
local lastIndex
while true do
-- 步骤 0:在执行任何操作之前先淡出
fadeOut:Play()
task.wait(tweenInfo.Time)
-- 步骤 1:选择不是上一个显示的内容
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- 确保下次不显示相同的内容
lastIndex = index
-- 步骤 2:展示内容
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end文本中的表情符号
local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "我感觉 " .. mood .. "! " .. face
task.wait(1)
end
endTextColor
TextColor3
代码示例
倒计时文本
-- 将此代码放置在 TextLabel/TextButton 内的 LocalScript 中
local textLabel = script.Parent
-- 一些我们用于 TextColor3 的颜色
local colorNormal = Color3.new(0, 0, 0) -- 黑色
local colorSoon = Color3.new(1, 0.5, 0.5) -- 红色
local colorDone = Color3.new(0.5, 1, 0.5) -- 绿色
-- 无限循环
while true do
-- 从 10 倒数到 1
for i = 10, 1, -1 do
-- 设置文本
textLabel.Text = "时间: " .. i
-- 根据剩余时间设置颜色
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "开始!"
textLabel.TextColor3 = colorDone
task.wait(2)
endTextWrap