概要
屬性
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