TextBox

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

A 텍스트박스 는 플레이어가 텍스트 입력을 제공할 수 있게 합니다.단일 TextBox를 클릭하거나 탭하거나 게임패드 선택으로 포커스를 맞출 수 있다는 점을 제외하고는 TextButton와 유사하게 동작합니다.포커스 중에 플레이어는 키보드를 사용하여 Text 속성을 변경할 수 있습니다.

  • 텍스트가 없으면 PlaceholderText 가 표시됩니다. 이는 플레이어에게 입력해야 하는 데이터의 종류나 형식을 알려주는 데 유용합니다.
  • 기본적으로 ClearTextOnFocus 속성이 활성화되어 텍스트박스가 포커스될 때 기존 텍스트가 없는지 확인합니다.플레이어가 편집할 수 있는 텍스트에는 이 기능이 원하지 않을 수 있습니다.
  • MultiLine 속성을 사용하면 플레이어가 새줄 문자로 여러 줄의 텍스트를 입력할 수 있습니다(\n).

The ContextActionService 는 TextBox 키바인드를 존중하고 키 누르기 이벤트가 ContextActionService:BindAction() 에 바인딩된 작업으로 자동으로 전달되지 않도록 방지합니다.UserInputService.InputBegan 및 관련 이벤트는 텍스트박스가 포커스에 있는 동안에도 여전히 발생합니다.

초점 상태

텍스트박스의 초점 상태를 감지하고 변경할 수 있습니다:

  • 대화 상자가 표시될 때 CaptureFocus를 사용하여 플레이어가 사용 가능해지면 텍스트박스를 클릭할 필요가 없도록 할 수 있으며, ContextActionService:BindAction()를 사용하여 이 함수를 사용하여 텍스트박스를 포커스하는 특정 키를 바인딩할 수 있습니다.텍스트박스가 초점에 들어오면 Focused 이벤트가 발생합니다.
  • IsFocused를 사용하여 특정 TextBox가 포커스에 있는지 확인할 수 있습니다. 또는 UserInputService:GetFocusedTextBox()를 사용하여 어떤 TextBox가 포커스에 있는지 확인할 수 있습니다.
  • 플레이어가 텍스트 입력을 완료하면 이벤트가 발생하여 사용자가 텍스트와 함께 를 누르고 초점 손실을 일으킨 것을 나타냅니다.모바일 및 콘솔에서 화면 키보드를 사용할 때, ReturnPressedFromOnScreenKeyboard 또한 발생할 수 있습니다.
  • 게임 플레이 중에 더 중요한 문제가 발생하면 TextBox의 ReleaseFocus를 줄여서 플레이어의 키보드 입력이 게임으로 돌아옵니다.

텍스트 편집

텍스트박스는 CursorPositionSelectionStart 속성을 통해 텍스트 선택을 지원합니다.GetPropertyChangedSignal 을 사용하여 선택이 변경될 때를 감지할 수 있습니다.또한 플레이어가 TextBox 내에서 텍스트를 복사하고 붙여넣어 기본 클립보드 지원을 활성화할 수 있습니다.

텍스트 필터링 알림 플레이어 간 커뮤니케이션을 용이하게 하는 텍스트, 예를 들어 사용자 지정 채팅이나 네임태그,는 TextService:FilterStringAsync() 또는 Chat:FilterStringAsync()을 사용하여 해당 텍스트를 적절하게 필터링해야 합니다.제대로 수행되지 않으면 게임에 조정 액션적용될 수 있습니다.

코드 샘플

This code sample creates a password-like interface for a TextBox, giving visual feedback on the player's input.

TextBox Secret Word

-- Place this code in a LocalScript inside a TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- white
local colorWrong = Color3.new(1, 0, 0) -- red
local colorCorrect = Color3.new(0, 1, 0) -- green
-- Initialize the state of the textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "What is the secret word?"
textBox.BackgroundColor3 = colorNormal
local function onFocused()
textBox.BackgroundColor3 = colorNormal
end
local function onFocusLost(enterPressed, _inputObject)
if enterPressed then
local guess = textBox.Text
if guess == secretWord then
textBox.Text = "ACCESS GRANTED"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCESS DENIED"
textBox.BackgroundColor3 = colorWrong
end
else
-- The player stopped editing without pressing Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

요약

속성

속성GuiObject에서 상속되었습니다속성GuiBase2d에서 상속되었습니다

메서드

  • 클라이언트가 텍스트박스에 집중하도록 강제합니다.

  • 텍스트박스가 포커스된 경우 true를 반환하고, 그렇지 않은 경우 false를 반환합니다.

  • ReleaseFocus(submitted : boolean):()

    클라이언트가 TextBox의 초점을 맞추지 않도록 강제합니다.

메서드GuiObject에서 상속되었습니다

이벤트

이벤트GuiObject에서 상속되었습니다이벤트GuiBase2d에서 상속되었습니다

속성

ClearTextOnFocus

병렬 읽기

텍스트박스를 클릭하면 해당 속성이 지워지는지 여부를 결정합니다 TextBox.Text

ContentText

읽기 전용
복제되지 않음
병렬 읽기

CursorPosition

병렬 읽기

이 속성은 텍스트 커서의 바이트 오프셋을 결정하거나, -1 는 현재 TextBox 가 편집되지 않는 경우에는 바이트입니다.값 1 은 속성 Text 의 첫 바이트 앞의 위치를 나타냅니다.SelectionStart 속성과 함께 사용하면 TextBox 내에서 선택한 텍스트를 모두 가져오고 설정할 수 있습니다.

이 속성의 단위는 바이트 이고, 이모티콘과 같은 많은 유니코드 문자는 1바이트보다 깁니다.예를 인스턴스, 플레이어가 "Hello👋"("Hello"에 손 웨이브 신호가 즉시 이어지면)를 입력하면 커서 위치가 10가 되고, 4바이트의 이모티콘을 사용하기 때문에 7가 아닙니다.

코드 샘플

This code sample demonstrates reading the current selection of a TextBox using CursorPosition() and SelectionStart().

TextBox Selections

local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("No selection")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('The selection is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)
숨김
복제되지 않음
병렬 읽기

글꼴 속성은 UI 요소가 텍스트를 렌더링하는 데 사용할 여러 가지 미리 정의된 fonts 중 하나를 선택합니다.일부 글꼴에는 대담한, 이탈릭 및/또는 가벼운 변형이 있습니다(글꼴 무게 또는 글꼴 스타일 속성이 없기 때문에).

유산" 서체를 제외하고 각 서체는 줄 높이가 TextBox.TextSize 속성과 동일한 텍스트를 렌더링합니다.코드 글꼴은 단일 공간 글꼴입니다.각 캐릭터가 정확히 같은 너비와 높이 비율인 1:2를 갖고 있는 독특한 속성이 있습니다.각 문자의 너비는 약 TextBox.TextSize 속성의 절반입니다.

이 속성은 TextBox.FontFace 속성과 동기화되어 유지됩니다. 글꼴을 설정할 때 FontFace는 Font.fromEnum(value)로 설정됩니다.

코드 샘플

This code sample sets a parent TextLabel's Font and Text properties to all the different fonts available.

Cycle Font

local textLabel = script.Parent
while true do
-- Iterate over all the different fonts
for _, font in pairs(Enum.Font:GetEnumItems()) do
textLabel.Font = font
textLabel.Text = font.Name
task.wait(1)
end
end

This code sample renders a list of all the available fonts.

Show All Fonts

local frame = script.Parent
-- Create a TextLabel displaying each font
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Set the text properties
textLabel.Text = font.Name
textLabel.Font = font
-- Some rendering properties
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Size the frame equal to the height of the text
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Add to the parent frame
textLabel.Parent = frame
end
-- Layout the frames in a list (if they aren't already)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end

FontFace

병렬 읽기

FontFace 속성은 Font 속성과 유사하지만 폰트가 Font 열거형에 없는 경우 폰트를 설정할 수 있습니다.

이 속성은 TextBox.Font 속성과 동기화됩니다.FontFace를 설정할 때 글꼴은 해당 열거형 값으로 설정되거나, 일치하는 항목이 없으면 Enum.Font.Unknown로 설정됩니다.

LineHeight

병렬 읽기

글꼴의 줄 크기의 배수로 줄 높이를 제어하여 TextBox 에서 텍스트 줄 간격을 확장하고, 글꼴의 줄 크기의 배수로 줄 높이를 제어합니다.유효한 값은 1.0에서 3.0 사이이며, 기본값은 1.0입니다.

MaxVisibleGraphemes

병렬 읽기

이 속성은 최대 그래피즘(또는 텍스트 단위) 수를 제어하여 TextBox에 표시되는지 여부에 관계없이 TextBox.PlaceholderText 또는 TextBox.Text을 표시합니다.

속성을 변경하면 표시되는 그래픽의 위치나 크기가 변경되지 않습니다. 레이아웃은 모든 그래픽이 표시되는 것처럼 계산됩니다.

속성을 -1로 설정하면 제한이 해제되고 전체 TextBox.Text 가 표시됩니다.

MultiLine

병렬 읽기

TextBox에 진실로 설정되면 텍스트가 여러 줄로 이동할 수 있습니다. 이렇게 하면 플레이어가 엔터 키를 사용하여 새 줄로 이동할 수 있습니다.

OpenTypeFeatures

병렬 읽기

OpenTypeFeaturesError

읽기 전용
복제되지 않음
병렬 읽기

PlaceholderColor3

병렬 읽기

TextBox에 아직 텍스트가 입력되지 않은 경우 사용되는 텍스트 색상을 설정합니다.

PlaceholderText

병렬 읽기

TextBox에 아직 텍스트가 입력되지 않은 경우 표시되는 텍스트를 설정합니다.

RichText

병렬 읽기

이 속성은 TextBox 가 부자 텍스트 서식 지정을 사용하여 TextBox.Text 문자열을 렌더링하는지 여부를 결정합니다.부유한 텍스트는 간단한 마크업 태그를 사용하여 문자열의 섹션을 볼드, 이탤릭, 특정 색상 등으로 스타일링합니다.

Rich Text를 사용하려면 단순히 TextBox.Text 문자열에 서식 태그를 포함하면 됩니다.

TextBox에 이 속성이 활성화되어 있고 상자가 초점을 얻을 때, 사용자는 모든 서식 태그를 포함하여 완전한 XML 문자열을 편집하고 상호 작용할 수 있습니다.초점이 손실되면 텍스트가 자동으로 태그를 분석하고 풍부한 텍스트로 렌더링합니다.

SelectionStart

병렬 읽기

텍스트 선택의 시작 위치를 결정하거나 TextBox에 선택된 텍스트 범위가 없는 경우 -1을 합니다.값이 -1이거나 CursorPosition 에 해당하면 텍스트 범위가 선택되지 않습니다.이 속성은 CursorPosition과 동일한 위치 논리를 사용합니다.커서가 선택 항목의 시작에 있으면 SelectionStart가 CursorPosition보다 크고, 커서가 종료있으면 CursorPosition보다 작습니다.

코드 샘플

This code sample demonstrates reading the current selection of a TextBox using CursorPosition() and SelectionStart().

TextBox Selections

local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("No selection")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('The selection is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput

병렬 읽기

설정을 true로 설정하면 플랫폼에 네이티브로 입력되고 Roblox의 기본 키보드가 사용되지 않습니다.

Text

병렬 읽기

텍스트 속성은 UI 요소에서 렌더링된 콘텐츠를 결정합니다.화면에 렌더링된 문자열의 시각적 속성은 TextBox.TextColor3 , TextBox.TextTransparency , TextBox.TextSize , TextBox.Font , TextBox.TextScaled , TextBox.TextWrapped , TextBox.TextXAlignmentTextBox.TextYAlignment에 의해 결정됩니다.

예를 들어, 😃와 같은 이모지와 다른 기호를 렌더링할 수 있습니다.이러한 특수 기호는 TextBox.TextColor3 속성에 영향을 받지 않습니다.이들은 ScriptLocalScript 개체와 속성 창 내의 필드에 붙여넣을 수 있습니다.

이 속성에는 줄바꿈 문자가 포함될 수 있지만 속성 창에서 줄바꿈 문자를 입력할 수는 없습니다.마찬가지로, 이 속성에는 탭 문자가 포함될 수 있지만 대신 공백으로 렌더링됩니다.

코드 샘플

This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.

Fading Banner

local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"Welcome to my game!",
"Be sure to have fun!",
"Please give suggestions!",
"Be nice to other players!",
"Don't grief other players!",
"Check out the shop!",
"Tip: Don't die!",
}
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
-- Step 0: Fade out before doing anything
fadeOut:Play()
task.wait(tweenInfo.Time)
-- Step 1: pick content that wasn't the last displayed
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- Make sure we don't show the same thing next time
lastIndex = index
-- Step 2: show the content
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

local textLabel = script.Parent
textLabel.Text = "Kaboom!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
end

This code sample renders a list of all the available fonts.

Show All Fonts

local frame = script.Parent
-- Create a TextLabel displaying each font
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Set the text properties
textLabel.Text = font.Name
textLabel.Font = font
-- Some rendering properties
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Size the frame equal to the height of the text
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Add to the parent frame
textLabel.Parent = frame
end
-- Layout the frames in a list (if they aren't already)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end

This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.

Long Text Wrapping

local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end

This code sample demonstrates emoji rendering using the Text property.

Emoji in Text

local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "I am feeling " .. mood .. "! " .. face
task.wait(1)
end
end

TextBounds

읽기 전용
복제되지 않음
병렬 읽기

읽기 전용 속성 TextBounds는 오프셋에서 렌더링된 텍스트의 절대 크기를 반영합니다.즉, 텍스트를 직사각형에 맞추려고 시도한다면, 이 속성은 텍스트를 맞추기 위해 필요한 최소 직사각형 크기를 반영합니다.

TextService:GetTextSize() 를 사용하여 텍스트랩에 문자열을 주어 텍스트 경계가 무엇이 될지 예측할 수 있습니다, TextBox.Font , TextBox.TextSize 및 프레임 크기.

코드 샘플

This code sample dynamically resizes a TextLabel, TextButton or TextBox to match the size of its TextBounds. Try changing the minimum width/height and pasting into a LocalScript in a TextBox.

Dynamic TextBox Size

local textBox = script.Parent
-- The smallest the TextBox will go
local minWidth, minHeight = 10, 10
-- Set alignment so our text doesn't wobble a bit while we type
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextYAlignment = Enum.TextYAlignment.Top
local function updateSize()
textBox.Size = UDim2.new(0, math.max(minWidth, textBox.TextBounds.X), 0, math.max(minHeight, textBox.TextBounds.Y))
end
textBox:GetPropertyChangedSignal("TextBounds"):Connect(updateSize)

TextColor3

병렬 읽기

이 속성은 모든 GuiObject 요소에 의해 렌더링된 텍스트의 색을 결정합니다.이 속성과 TextBox.Font, TextBox.TextSizeTextBox.TextTransparency 는 텍스트의 시각적 속성을 결정합니다.텍스트는 텍스트 스트로크 후에 렌더링됩니다(TextBox.TextStrokeColor3).

플레이어가 쉽게 읽을 수 있는 텍스트가 중요합니다! 하얀색, 회색 또는 검은색과 같이 포화도가 적은 색을 선택하십시오.텍스트의 색이 UI 요소의 TextBox.BackgroundColor3에 의해 대조되는지 확인하십시오.요소에 투명한 배경이 있는 경우 검은색 TextBox.TextStrokeColor3를 적용하여 뒤에 있는 3D 세계와 텍스트의 대조를 돕습니다.

코드 샘플

This code sample, when placed within a TextBox, will turn the text color red if the typed string contains no vowels (A, E, I, O or U).

Vowel Detector

local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Check for vowels
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Red
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

This code sample creates a password-like interface for a TextBox, giving visual feedback on the player's input.

TextBox Secret Word

-- Place this code in a LocalScript inside a TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- white
local colorWrong = Color3.new(1, 0, 0) -- red
local colorCorrect = Color3.new(0, 1, 0) -- green
-- Initialize the state of the textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "What is the secret word?"
textBox.BackgroundColor3 = colorNormal
local function onFocused()
textBox.BackgroundColor3 = colorNormal
end
local function onFocusLost(enterPressed, _inputObject)
if enterPressed then
local guess = textBox.Text
if guess == secretWord then
textBox.Text = "ACCESS GRANTED"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCESS DENIED"
textBox.BackgroundColor3 = colorWrong
end
else
-- The player stopped editing without pressing Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

This code sample makes a TextLabel or TextButton count backwards from 10, setting the text color as it does so.

Countdown Text

-- Place this code in a LocalScript within a TextLabel/TextButton
local textLabel = script.Parent
-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorSoon = Color3.new(1, 0.5, 0.5) -- red
local colorDone = Color3.new(0.5, 1, 0.5) -- green
-- Loop infinitely
while true do
-- Count backwards from 10 to 1
for i = 10, 1, -1 do
-- Set the text
textLabel.Text = "Time: " .. i
-- Set the color based on how much time is left
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "GO!"
textLabel.TextColor3 = colorDone
task.wait(2)
end

This code sample mirrors the contents of a StringValue into a TextLabel, updating and setting the color of the text as it changes.

Game State Text

local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Place a StringValue called "GameState" in the ReplicatedStorage
local vGameState = ReplicatedStorage:WaitForChild("GameState")
-- Place this code in a TextLabel
local textLabel = script.Parent
-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorCountdown = Color3.new(1, 0.5, 0) -- orange
local colorRound = Color3.new(0.25, 0.25, 1) -- blue
-- We'll run this function to update the TextLabel as the state of the
-- game changes.
local function update()
-- Update the text
textLabel.Text = "State: " .. vGameState.Value
-- Set the color of the text based on the current game state
if vGameState.Value == "Countdown" then
textLabel.TextColor3 = colorCountdown
elseif vGameState.Value == "Round" then
textLabel.TextColor3 = colorRound
else
textLabel.TextColor3 = colorNormal
end
end
-- Pattern: update once when we start and also when vGameState changes
-- We should always see the most updated GameState.
update()
vGameState.Changed:Connect(update)

TextDirection

병렬 읽기

TextEditable

병렬 읽기

텍스트 편집 가능 사용자가 입력을 통해 Text를 변경할 수 있는지 여부를 결정합니다.이 속성이 비활성화되면 ClearTextOnFocus 를 비활성화하는 것이 좋습니다. 그렇지 않으면 텍스트가 포커스에서 지워질 수 있습니다.이 속성은 게임 내에서 복사할 수 있는 읽기 전용 TextBox를 만드는 데 유용합니다.

TextFits

읽기 전용
복제되지 않음
병렬 읽기

텍스트가 TextBox의 제약 조건에 맞는지 여부.

TextScaled

병렬 읽기

TextScaled를 사용하는 대신, 가능한 최고의 시각적 결과를 제공하는 새로운 방법인 AutomaticSize를 고려하는 것이 좋습니다.

TextScaled 속성은 텍스트가 UI 요소 전체의 공간을 채우도록 확장되는지 여부를 결정합니다.이 설정이 활성화되면 TextBox.TextSize 가 무시되고 TextBox.TextWrapped 가 자동으로 활성화됩니다.이 속성은 BillboardGuis 내의 텍스트 렌더링 UI 요소에 유용합니다.

이 속성이 화면 공간 UI로 사용될 때, 가능한 텍스트 크기 범위를 제한하기 위해 UITextSizeConstraint를 사용하는 것이 바람직할 수 있습니다.

텍스트 확장 및 자동 크기

개발자는 TextScaled의 사용을 피하고 대신 AutomaticSize 속성을 활용하여 UI를 조정하는 것이 좋습니다.다음은 두 속성 간의 핵심 차이점입니다:

  • TextScaled는 콘텐츠(텍스트)를 확장하여 UI를 수용합니다. 신중하게 고려하지 않으면 너무 작게 확장되면 일부 텍스트가 읽을 수 없게 될 수 있습니다.
  • 자동 크기 조정은 UI를 조정하여 콘텐츠를 수용합니다.

자동 크기를 사용하면 일관된 글꼴 크기를 유지하면서 콘텐츠(텍스트)를 수용하도록 UI를 조정할 수 있습니다.자동 크기 조정 방법에 대한 자세한 정보는 UI 자동 크기 문서를 참조하십시오.

TextScaled와 AutomaticSize를 동일한 UI 개체에 적용하지 않는 것이 좋습니다. 두 속성을 모두 적용하는 경우:

  • 자동 크기는 사용 가능한 공간의 최대 양을 결정합니다(이 경우 텍스트) GuiObject 가 사용할 수 있는
  • TextScaled는 AutomaticSize에서 결정한 사용 가능한 공간을 사용하여 글꼴 크기를 확장하여 사용 가능한 공간에 맞추고, 크기 제한이 없으면 최대 글꼴 크기(100)까지 확장합니다.
  • 최종 결과는 다음과 같습니다: 텍스트가 100픽셀 크기로 이동하고 UI 개체가 해당 텍스트에 맞게 확장됩니다.

자동 크기와 텍스트 크기를 동시에 사용하면 자동 크기가 끄기경우보다 크게 차이가 발생할 수 있습니다.

코드 샘플

This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.

Long Text Wrapping

local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end

TextSize

병렬 읽기

TextSize 속성은 렌더링된 텍스트 한 줄의 오프셋 높이를 결정합니다.단위는 오프셋에 있으며(대부분의 문서 편집 프로그램에서 사용되는 포인트는 아님),레거시 폰트는 이 속성을 보유하지 않습니다.

코드 샘플

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

local textLabel = script.Parent
textLabel.Text = "Kaboom!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
end

TextStrokeColor3

병렬 읽기

TextStrokeColor3 속성은 렌더링된 텍스트의 스트로크 또는 윤곽의 색을 설정합니다.이 속성과 TextBox.TextStrokeTransparency 은 텍스트 스트로크의 시각적 속성을 결정합니다.

텍스트 스트로크는 일반 텍스트 전에 렌더링되며 각 방향의 +/- 1픽셀 오프셋에서 동일한 텍스트의 4개 렌더링입니다.텍스트 스트로크 렌더링은 독립적으로 및 동일하게 TextBox.TextColor3TextBox.TextTransparency에서 작동합니다.

코드 샘플

This code sample oscillates a TextLabel's TextStrokeTransparency so that it blinks the highlight of a text.

Text Highlight Oscillation

local textLabel = script.Parent
-- How fast the highlight ought to blink
local freq = 2
-- Set to yellow highlight color
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin oscillates from -1 to 1, so we change the range to 0 to 1:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
end

TextStrokeTransparency

병렬 읽기

TextStrokeTransparency 속성은 렌더링된 텍스트의 스트로크 또는 윤곽의 투명도를 설정합니다.이 속성과 TextBox.TextStrokeColor3 은 텍스트 스트로크의 시각적 속성을 결정합니다.

텍스트 스트로크는 일반 텍스트 전에 렌더링되며 각 방향의 +/- 1픽셀 오프셋에서 동일한 텍스트의 4개 렌더링입니다.텍스트 스트로크 렌더링은 독립적으로 및 동일하게 TextBox.TextColor3TextBox.TextTransparency에서 작동합니다.텍스트 스트로크는 단순히 동일한 투명도의 여러 렌더링이므로 이 속성은 본질적으로 4배 증가합니다(예:텍스트 스트로크 투명도 0.5가 0.0625나 0.5^4의 텍스트 투명도와 비슷하게 보입니다.따라서 더 미묘한 효과를 위해 텍스트 스트로크 투명도를 0.75에서 1 사이의 값으로 설정하는 것이 좋습니다.

코드 샘플

This code sample oscillates a TextLabel's TextStrokeTransparency so that it blinks the highlight of a text.

Text Highlight Oscillation

local textLabel = script.Parent
-- How fast the highlight ought to blink
local freq = 2
-- Set to yellow highlight color
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin oscillates from -1 to 1, so we change the range to 0 to 1:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
end

TextTransparency

병렬 읽기

TextColor3 속성은 UI 요소에서 렌더링된 모든 텍스트의 투명도를 결정합니다.이 속성과 함께 TextBox.Font, TextBox.TextSizeTextBox.TextColor3 는 텍스트의 시각적 속성을 결정합니다.텍스트는 텍스트 스트로크 후에 렌더링됩니다(TextBox.TextStrokeTransparency).

숫자 포 루프를 사용하여 텍스트를 사라지게 하는 것은 화면에 나타나는 텍스트에 플레이어의 주의를 끌기 위한 환상적인 방법입니다.


-- Count backwards from 1 to 0, decrementing by 0.1
for i = 1, 0, -0.1 do
textLabel.TextTransparency = i
task.wait(0.1)
end

코드 샘플

This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.

Fading Banner

local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"Welcome to my game!",
"Be sure to have fun!",
"Please give suggestions!",
"Be nice to other players!",
"Don't grief other players!",
"Check out the shop!",
"Tip: Don't die!",
}
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
-- Step 0: Fade out before doing anything
fadeOut:Play()
task.wait(tweenInfo.Time)
-- Step 1: pick content that wasn't the last displayed
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- Make sure we don't show the same thing next time
lastIndex = index
-- Step 2: show the content
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

local textLabel = script.Parent
textLabel.Text = "Kaboom!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
end

TextTruncate

병렬 읽기

이 TextBox에 표시된 텍스트의 잘림을 제어합니다.

TextWrapped

병렬 읽기

활성화되면 이 속성은 요소의 공간 내에서 여러 줄에 텍스트를 렌더링하여 GUI 요소의 크기가 결코 초과되지 않도록 합니다.

이는 긴 텍스트 줄을 여러 줄로 나누어 달성됩니다.줄 바꿈은 공백을 선호하며; 긴 단어가 요소 너비를 초과하면 그 단어가 여러 줄로 분할됩니다.

추가 줄 분할로 텍스트(TextBox.TextBounds의 Y 구성 요소)의 세로 높이가 요소의 세로 높이(GuiBase2d.AbsoluteSize의 Y 구성 요소)를 초과하면 해당 줄은 전체렌더링되지 않습니다.

코드 샘플

This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.

Long Text Wrapping

local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end

TextXAlignment

병렬 읽기

TextXAlignment는 UI 요소 공간 내에 렌더링된 텍스트의 가로 정렬(X축)을 결정합니다.왼쪽, 오른쪽 및 중앙 값으로 CSS 텍스트 정렬 속성과 유사하게 작동합니다(정렬 옵션은 없음).왼쪽과 오른쪽의 경우 텍스트는 왼쪽/오른쪽 텍스트 경계가 UI 요소 직사각형의 가장자리에 닿도록 렌더링됩니다.센터에서는 각 텍스트 줄이 UI 요소 직사각형의 중앙에 정렬됩니다.

이 속성은 TextBox.TextYAlignment와 함께 사용되어 두 축에서 텍스트 정렬을 완전히 결정합니다.이 속성은 읽기 전용 속성 TextBox.TextBoundsTextBox.TextFits에 영향을 주지 않습니다.

코드 샘플

This code sample shows all the different text alignment combinations by iterating over each enum item. It is meant to be placed within a TextLabel, TextButton or TextBox.

Text Alignment

-- Paste this in a LocalScript within a TextLabel/TextButton/TextBox
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
-- Iterate over both TextXAlignment and TextYAlignment enum items
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

TextYAlignment

병렬 읽기

TextYAlignment는 UI 요소 공간 내에 렌더링된 텍스트의 세로 정렬(Y축)을 결정합니다.위와 아래의 경우 텍스트가 맨 위/맨 아래 텍스트 경계가 UI 요소 직사각형의 가장자리에 닿도록 렌더링됩니다.센터의 경우 텍스트가 렌더링되어 텍스트의 상단 경계에서 요소 상단까지 동일한 공간이 있고 텍스트의 하단 경계에서 요소 하단까지 동일한 공간이 있습니다.

이 속성은 TextBox.TextXAlignment와 함께 사용되어 두 축에서 텍스트 정렬을 완전히 결정합니다.이 속성은 읽기 전용 속성 TextBox.TextBoundsTextBox.TextFits에 영향을 주지 않습니다.

코드 샘플

This code sample shows all the different text alignment combinations by iterating over each enum item. It is meant to be placed within a TextLabel, TextButton or TextBox.

Text Alignment

-- Paste this in a LocalScript within a TextLabel/TextButton/TextBox
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
-- Iterate over both TextXAlignment and TextYAlignment enum items
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

메서드

CaptureFocus

()

클라이언트가 텍스트박스에 집중하도록 강제합니다.


반환

()

코드 샘플

This code sample causes the client to focus on the parent TextBox when the Q key is pressed by the player.

TextBox:CaptureFocus

local ContextActionService = game:GetService("ContextActionService")
local ACTION_NAME = "FocusTheTextBox"
local textBox = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_NAME and inputState == Enum.UserInputState.End then
textBox:CaptureFocus()
end
end
ContextActionService:BindAction(ACTION_NAME, handleAction, false, Enum.KeyCode.Q)

IsFocused

텍스트박스가 포커스된 경우 true를 반환하고, 그렇지 않은 경우 false를 반환합니다.


반환

ReleaseFocus

()

클라이언트가 TextBox의 초점을 맞추지 않도록 강제합니다. submitted 매개변수를 사용하면 enterPressed 매개변수를 이벤트 TextBox.FocusLost에서 재정의할 수 있습니다.

이 항목은 온라인 모드에서 예상대로 작동하려면 LocalScript와 함께 사용해야 합니다.

아래 표시된 코드는 클라이언트가 'TextBox'를 선택한 후 5초 동안 초점을 맞추지 않도록 강제합니다:


local TextBox = script.Parent
TextBox.Focused:Connect(function()
wait(5)
TextBox:ReleaseFocus()
end)

위의 예제는 TextBox의 자식으로 로컬 스크립트에 있다고 가정합니다.

매개 변수

submitted: boolean
기본값: false

반환

()

코드 샘플

The code shown below will force the client to unfocus the 'TextBox' 5 seconds after it's selected:

TextBox:ReleaseFocus

local textBox = script.Parent
local function onFocused()
task.wait(5)
textBox:ReleaseFocus()
end
textBox.Focused:Connect(onFocused)

이벤트

FocusLost

클라이언트가 TextBox에서 초점을 떠날 때 발생하며, 일반적으로 클라이언트가 TextBox 외부를 클릭하거나 탭할 때 발생합니다.TextBox가 사용자에게 초점을 맞추도록 강제하면 이 또한 발생합니다.

TextBox가 초점을 얻고 잃을 때를 추적하기 위해 TextBox.Focused와 함께 사용할 수 있습니다.

사용자 입력 서비스 서비스에 의존하는 유사한 기능은 UserInputService.TextBoxFocusedUserInputService.TextBoxFocusReleased에 참조하십시오.

이 이벤트는 LocalScript에서만 발생합니다.

매개 변수

enterPressed: boolean

클라이언트가 입력을 누르고 초점을 잃었는지 여부를 나타내는 부울(true 또는 false).

inputThatCausedFocusLoss: InputObject

TextBox가 초점을 잃은 입력 유형을 나타내는 InputObject 인스턴스.


코드 샘플

The example shown below will print "Focus was lost because enter was pressed!" whenever the TextBox loses focus as a result of the enter key being pressed.

TextBox.FocusLost1

local gui = script.Parent
local textBox = gui.TextBox
local function focusLost(enterPressed)
if enterPressed then
print("Focus was lost because enter was pressed!")
else
print("Focus was lost without enter being pressed")
end
end
textBox.FocusLost:Connect(focusLost)

This example works when placed in a LocalScript that is the child of a TextBox. When the TextBox loses focus, the example prints either:

  1. "Player pressed Enter" - if the TextBox lost focus because the player pressed the Enter key. or
  2. "Player pressed InputObject.KeyCode" - where "KeyCode" is the InputObject KeyCode property of the input that caused the TextBox to lose focus. For example, pressing the Escape (esc) key to exit TextBox focus returns an InputObject instance with the KeyCode 'InputObject.Escape'.
FocusLost

local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Player pressed Enter")
else
print("Player pressed", inputThatCausedFocusLost.KeyCode)
end
end
textBox.FocusLost:Connect(onFocusLost)

Focused

TextBox가 초점을 얻을 때 화재 - 일반적으로 클라이언트가 텍스트박스를 클릭하거나 탭하여 텍스트 입력을 시작할 때.TextBox가 사용자에게 초점을 맞추도록 강제하면 이 또한 발생합니다.

TextBox가 초점을 얻고 잃을 때를 추적하기 위해 TextBox.FocusLost와 함께 사용할 수 있습니다.

사용자 입력 서비스 서비스에 의존하는 유사한 기능은 UserInputService.TextBoxFocusedUserInputService.TextBoxFocusReleased에 참조하십시오.

이 이벤트는 LocalScript에서만 발생합니다.


코드 샘플

This example works when placed in a LocalScript that is the child of a TextBox. When the TextBox gains focus, the example prints "Focus".

Focus

local textBox = script.Parent
local function onFocused()
print("Focused")
end
textBox.Focused:Connect(onFocused)

ReturnPressedFromOnScreenKeyboard