Text Label
*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.
요약
속성
상속된 멤버
코드 샘플
게임 상태 텍스트
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- "GameState"라는 StringValue를 ReplicatedStorage에 배치합니다.
local vGameState = ReplicatedStorage:WaitForChild("GameState")
-- 이 코드를 TextLabel에 배치합니다.
local textLabel = script.Parent
-- TextColor3와 함께 사용할 몇 가지 색상
local colorNormal = Color3.new(0, 0, 0) -- 검정색
local colorCountdown = Color3.new(1, 0.5, 0) -- 주황색
local colorRound = Color3.new(0.25, 0.25, 1) -- 파란색
-- 게임 상태가 변경될 때 TextLabel을 업데이트하기 위해 이 함수를 실행합니다.
local function update()
-- 텍스트 업데이트
textLabel.Text = "상태: " .. vGameState.Value
-- 현재 게임 상태에 따라 텍스트의 색상을 설정합니다.
if vGameState.Value == "Countdown" then
textLabel.TextColor3 = colorCountdown
elseif vGameState.Value == "Round" then
textLabel.TextColor3 = colorRound
else
textLabel.TextColor3 = colorNormal
end
end
-- 패턴: 시작할 때 한 번 업데이트하고 vGameState가 변경될 때도 업데이트합니다.
-- 항상 가장 최신의 GameState를 볼 수 있어야 합니다.
update()
vGameState.Changed:Connect(update)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
end폰트 순환
local textLabel = script.Parent
while true do
-- 모든 다양한 폰트를 반복합니다
for _, font in pairs(Enum.Font:GetEnumItems()) do
textLabel.Font = font
textLabel.Text = font.Name
task.wait(1)
end
endFont Size
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
endText Bounds
코드 샘플
동적 텍스트 박스 크기
local textBox = script.Parent
-- 텍스트 박스의 최소 크기
local minWidth, minHeight = 10, 10
-- 텍스트가 입력하는 동안 흔들리지 않도록 정렬 설정
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextYAlignment = Enum.TextYAlignment.Top
local function updateSize()
textBox.Size = UDim2.fromOffset(math.max(minWidth, textBox.TextBounds.X), math.max(minHeight, textBox.TextBounds.Y))
end
textBox:GetPropertyChangedSignal("TextBounds"):Connect(updateSize)Text Color
Text Color3
코드 샘플
카운트다운 텍스트
-- 이 코드를 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)
endText Size
코드 샘플
"쿵!" 텍스트
local textLabel = script.Parent
textLabel.Text = "쿵!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
endText Stroke Transparency
코드 샘플
텍스트 하이라이트 진동
local textLabel = script.Parent
-- 하이라이트가 얼마나 빨리 깜빡일지
local freq = 2
-- 노란색 하이라이트 색상으로 설정
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin은 -1에서 1 사이에서 진동하므로, 범위를 0에서 1로 변경합니다:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
endText Wrap
Text Wrapped
코드 샘플
긴 텍스트 줄 바꿈
local textLabel = script.Parent
-- 이 텍스트 래핑 데모는 200x50 px 직사각형에서 가장 잘 보여집니다
textLabel.Size = UDim2.fromOffset(200, 50)
-- 내용을 나타내기 위한 일부 텍스트
local content = "여기 긴 문자열이 있습니다 "
.. "UI 요소의 너비를 초과할 것입니다 "
.. "그리고 줄 바꿈을 형성합니다. 긴 단락에 유용합니다 "
.. "정말 긴."
-- 두 글자씩 텍스트를 나타내는 함수
local function spellTheText()
-- 내용의 길이만큼 1부터 반복합니다
for i = 1, content:len() do
-- 내용의 부분 문자열을 가져옵니다: 1부터 i까지
textLabel.Text = content:sub(1, i)
-- 텍스트가 상자에 맞지 않으면 색상을 변경합니다
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- 검정색
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- 빨간색
end
-- 짝수 길이에서 잠시 대기합니다
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- 스케일/래핑 없이 텍스트를 나타냅니다
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- 래핑을 켜고 텍스트를 나타냅니다
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- 텍스트 스케일링을 켜고 텍스트를 나타냅니다
-- 참고: 텍스트가 UI 요소 내에 맞추기 위해 축소되어야 할 때 텍스트가 빨간색으로 변합니다 (TextFits = false).
textLabel.TextScaled = true
-- 참고: TextScaled = true일 때 TextWrapped가 암묵적으로 활성화됩니다
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
endText X Alignment
코드 샘플
텍스트 정렬
-- 이 코드를 TextLabel/TextButton/TextBox 안의 LocalScript에 붙여넣으세요
local textLabel = script.Parent
local function setAlignment(xAlign, yAlign)
textLabel.TextXAlignment = xAlign
textLabel.TextYAlignment = yAlign
textLabel.Text = xAlign.Name .. " + " .. yAlign.Name
end
while true do
-- TextXAlignment 및 TextYAlignment 열거형 항목을 모두 반복합니다
for _, yAlign in pairs(Enum.TextYAlignment:GetEnumItems()) do
for _, xAlign in pairs(Enum.TextXAlignment:GetEnumItems()) do
setAlignment(xAlign, yAlign)
task.wait(1)
end
end
end