TextBox
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
Bir Metin Kutusu , oyuncunun metin girişi yapmasına izin verir.Bir tek TextBox'un tıklayarak, dokunarak veya oyun kumandası seçimiyle odaklanması dışında, benzer şekilde davranır TextButton .Odaklanırken, oyuncu Text özelliğini değiştirmek için bir klavye kullanabilir.
- Metin yoksa, PlaceholderText görünecektir. Bu, oyunculara girmeleri gereken veri türü veya formatı konusunda yararlı bir uyarıdır.
- Varsayılan olarak, ClearTextOnFocus özelliği etkinleştirilir ve bir TextBox odaklandığında mevcut bir metin olmadığından emin olur.oyuncutarafından düzenlenebilecek metin için bu istenmeyebilir.
- The MultiLine özelliği, oyuncuların yeni satır karakterleriyle birden fazla satır metin girmesine izin verir (\n).
The ContextActionService onur TextBox tuş kombinasyonlarını ve otomatik olarak anahtar basma olaylarının ContextActionService:BindAction() ile bağlı eylemlere geçmesini engelleyecektir.UserInputService.InputBegan ve ilgili olaylar, bir TextBox odakta olduğu sürece hala ateşlenecek.
Odak Durumu
Bir TextBox'un odak durumunu tespit edip değiştirmek mümkündür:
- Bir diyalog göründüğünde CaptureFocus kullanabilirsiniz, böylece oyuncu mevcut olduğunda bir TextBox'a tıklamak zorunda kalmaz; bu işlevi kullanarak bir TextBox'a odaklanmak için belirli bir anahtarı bağlamak için ContextActionService:BindAction() kullanabilirsiniz.Bir TextBox odaklanınca, Focused etkinliği ateşlenir.
- Belli bir TextBox'un odakta olup olmadığını IsFocused kullanarak tespit edebilirsiniz. Alternatif olarak, herhangi bir TextBox'un odakta olup olmadığını kontrol etmek için UserInputService:GetFocusedTextBox() kullanılabilir.
- Oyuncu metin girişini bitirdiğinde, etkinliği ateşlenir, kullanıcının odak kaybına neden olan ile birlikte metin göndermek için basıp basmadığını gösterir.Mobil ve konsolda ekran klavyelerini kullanırken, ReturnPressedFromOnScreenKeyboard da ateşlenebilir.
- oynanışsırasında daha önemli bir konu ortaya çıkarsa, bir oyuncunun klavye girişi oyununuza geri döner, TextBox'un ReleaseFocus kısmını öyle yapabilirsiniz.
Metin Düzenleme
Bir TextBox, CursorPosition ve SelectionStart özellikleri aracılığıyla metin seçimi destekler.GetPropertyChangedSignal kullanarak, bir seçimin değiştiğini tespit edebilirsiniz.Ayrıca, oyuncuların bir TextBox içinde metin kopyalayıp yapıştırması ve temel klip desteği sağlaması mümkündür.
Metin Filtreleme Bildirimi Oyuncudan oyuncuya iletişimi kolaylaştıran metinler, özel sohbet veya isim etiketleri gibi, bu tür bir metni doğru bir şekilde filtrelemelidir TextService:FilterStringAsync() veya Chat:FilterStringAsync() .Bu doğru yapılmazsa, oyununuz moderasyon aksiyonalabilir.
Kod Örnekleri
This code sample creates a password-like interface for a TextBox, giving visual feedback on the player's input.
-- 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)
Özet
Özellikler
Metin Kutusuna tıklamanın onun TextBox.Text özelliğini temizleyip temizlemeyeceğini belirler.
Metin imlecinin baytlarındaki ofsetini belirler veya -1 yoksa imleç yoktur.
Metin görüntülemek için kullanılan yazı tipini belirler.
Metin görüntülemek için kullanılan yazı tipini belirler.
TextBox içindeki metin satırları arasındaki boşluk ölçeklendirilir.
TextBox'nin gösterebileceği maksimum grafem sayısı.
Doğru ayarlanırsa, bir TextBox içindeki metin çoklu satırlara taşınabilir. Bu da oyuncuların yeni bir satıra geçmek için girme tuşunu kullanmasına izin verir.
TextBox'a henüz hiçbir metin girişi yapılmadığında kullanılacak yazı rengini ayarlar.
TextBox'a henüz hiçbir metin girişi yapılmadığında görüntülenen metni ayarlar.
TextBox'un zengin metin biçimlendirme kullanarak TextBox.Text dizeyi görüntüleyip görüntülemediğini belirler.
Bir metin seçiminin başlangıç konumunu veya hiçbir metin seçilmediğinde -1 belirler.
Doğru olarak ayarlanırsa, platforma yerleşik klavye yerine Roblox'un dahili olarak yüklendiği klavyesi kullanılır.
Arayüz öğesi tarafından görüntülenen dizeyi belirler.
Bir UI öğesinin metninin ofsetlerdeki boyutu.
Görüntülenen metinin rengini belirler.
Kullanıcının Text 'yi değiştirebileceğini belirler.
Metnin TextBox sınırlarına uyup uymadığı.
Metnin, onu görüntüleyen GUI nesnesine uyacak şekilde yeniden boyutlandırılıp yeniden boyutlandırılmadığını değiştirir.
Ofsetlerdeki metin yüksekliğini belirleyin.
Metin darbesinin (çizginin) rengini belirler (çizgi).
Metin darbesinin (çizginin) transparanlığını belirler (çizgi).
Rendelenmiş metnin transparanlığını belirler.
Bu TextBox'ta gösterilen metnin kısaltılmasını kontrol eder.
Metnin GuiObject öğe alanı içinde birden fazla satıra sarılıp sarılmadığını belirler ve fazla metni kısaltır.
Rendelenmiş metnin yatay hizalanmasını belirler.
Rendelenmiş metnin dikey yerleşimini belirler.
Özellikler
Bu UI öğesinin girişi alıp almadığını belirler.
Bir GuiObject 'in mutlak boyutuna göre kaynağı noktasını belirler, mutlak boyutuna göre.
Yeniden boyutlandırmanın çocuk içeriğine dayalı olup olmadığını belirler.
GuiObject arka plan rengini belirler.
GuiObject arka planının ve sınırının saydamlığını belirler.
GuiObject sınırının rengini belirler.
GuiObject sınırının boyutlarına göre nasıl düzenleneceğini belirler.
GuiObject sınırının piksel genişliğini belirler.
Ebeveyn bir GUI öğesinin sınırlarının dışında olup olmadığına bakarak altının GuiObjects renderlanması gereip geremediğini belirler.
oyuncumouse'unun GuiObject üzerinde aktif olarak basılıp basılmadığını belirler.
GuiButton ile etkileşime girilebilir olup olmadığını veya GuiState 'nin değişip değişmediğini belirler, ya da GuiObject 'nin değişip değişmediği.
Bir GuiObject ile kullanıldığında UIGridStyleLayout sıralama düzenini kontrol eder.
Oyun kolu seçicisi aşağıya kaydırıldığında seçilecek GuiObject ayarını ayarlar
Oyun kolu seçicisinin sola taşındığında seçilecek GuiObject ayarını ayarlar
Oyun kolu seçicisinin sağa taşındığında seçilecek GuiObject ayarını ayarlar
Oyun kolu seçicisi yukarı taşındığında seçilecek GuiObject ayarını ayarlar
GuiObject 'nin piksel ve skalar konumunu belirler.
GuiObject döndürüldüğünde döndürülen derece sayısını belirler.
GuiObject bir oyun kolu tarafından seçilebilir olup olmadığını belirleyin.
Oyun konsolları için kullanılan varsayılan seçim aksesuarlarını değiştirir.
Oyun kumanda UI seçimi tarafından seçilen GuiObjects sırası.
GuiObject 'nin piksel ve skalar büyüklüğünü belirler.
Size eksenlerini ayarlar, üzerinde ebeveynin boyutuna göre yapılacak GuiObject , ebeveynin boyutuna göre yapılacak
BackgroundTransparency ve TextTransparency 'in karışık bir özelliği.
GuiObject ve onun soyundakilerin render edilecek olup olmadığını belirler.
Bir GuiObject'nin diğerlerine göre hangi sırayla görüntüleneceğini belirler.
Özellikler
Bir GuiBase2d öğesinin gerçek ekran konumunu, piksel olarak tanımlar.
Bir GuiBase2d öğesinin gerçek ekran dönüşünü derecelerle tanımlar.
Bir GuiBase2d öğesinin gerçek ekran boyutunu, piksel olarak tanımlar.
true olarak ayarlanırsa, yerelleştirme bu GuiBase2d ve onun soyundakilere uygulanacaktır.
Bu GuiBase2d ve onun soyundakilere otomatik yerelleştirme uygulamak için kullanılacak bir LocalizationTable.
Aşağı yönünde oyun kolu seçim davranışını özelleştirir.
Oyun kolu seçim davranışını sol yönde özelleştirir.
Oyun kolu seçim davranışını doğru yönde özelleştirir.
Oyun kolu seçim davranışını yukarı yönünde özelleştirir.
Oyun kolu seçim hareketinin özelleştirilmesine izin verir.
Yöntemler
Müşteriyi TextBox'a odaklanmaya zorlar.
Metin kutusu odaklanmışsa gerçek döndürür, değilse yalan.
Müşteriyi TextBox'tan uzaklaştırmaya zorlar.
Yöntemler
- TweenPosition(endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
Bir GUI'yi yumuşakça yeni bir UDim2 'ye taşır.
- TweenSize(endSize : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
Bir GuiObject 'yi yumuşak bir şekilde yeni bir UDim2 'ye yeniden boyutlandırır.
- TweenSizeAndPosition(endSize : UDim2,endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
Bir GUI'yi yumuşakça yeni bir boyuta ve konuma taşır.
Olaylar
Müşteri odaklarını TextBox terk etmesine izin verdiğinde ateş eder.
TextBox odak kazandığında ateş eder.
Olaylar
Bir kullanıcı, İnsan-Bilgisayar Arayüzü cihazı aracılığıyla etkileşime başladığında ateş edilir (Fare düğmesi aşağı, dokunma başlar, klavye düğmesi aşağı, vb.).
Bir kullanıcı, İnsan-Bilgisayar Arayüzü cihazı aracılığıyla nasıl etkileşime girdiğini değiştirdiğinde ateş edilir (Fare düğmesü aşağı, dokunma başlar, klavye düğmesi aşağı, vb.).
Bir kullanıcı, İnsan-Bilgisayar Arayüzü cihazı aracılığıyla etkileşime son verdiğinde ateş edilir (Mouse düğmes aşağı, dokunma başlar, klavye düğmesi aşağı, vb.).
Bir kullanıcının fareini bir GUI öğesine taşıdığında ateş eder.
Bir kullanıcı GUI öğesinden fareni taşıdığında ateş eder.
Bir kullanıcı bir GUI öğesinin içindeyken fareyi hareket ettirdiğinde herhangi bir zamanda ateş eder.
Bir kullanıcı, fare bir GUI öğesinin üzerinde olduğunda fare tekerleğini geri sürüklediğinde ateş eder.
Bir kullanıcı, fare işaretçisi bir GUI öğesinin üzerinde olduğunda fare tekerleğini ileriye doğru kaydırdığında ateş eder.
GuiObject, Gamepad seçicisi ile odaklanırken ateş edildi.
Oyun Konsolu seçicisi GuiObject'e odaklanmayı bıraktığında ateş edilir.
Oyuncu başladığında, devam ettiğinde ve uzun süre UI öğesine basmayı bıraktığında ateş eder.
- TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal
Oyuncu UI öğesine parmağını hareket ettirdiğinde ateş eder.
- TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
Oyuncu, UI öğesinde iki parmağı kullanarak bir kıskaç veya çekme hareketi gerçekleştirdiğinde ateş eder.
- TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
Oyuncu, UI öğesinde iki parmağı kullanarak bir dönüş hareketi gerçekleştirdiğinde ateş eder.
Oyuncu UI öğesine kaydırma hareketi yaptığında ateş eder.
Oyuncu UI öğesine dokunma hareketi yaptığında ateş eder.
Olaylar
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
Oyun kolu seçimi, hareket eder, değişir veya bağlantılı GuiBase2d veya herhangi bir altın içinde değişir, bağlantılı GuiObjects .
Özellikler
ClearTextOnFocus
ContentText
CursorPosition
Kod Örnekleri
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)
Font
Kod Örnekleri
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
local frame = script.Parent
-- Her bir fontu gösteren bir TextLabel oluştur
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Metin özelliklerini ayarla
textLabel.Text = font.Name
textLabel.Font = font
-- Bazı renderleme özellikleri
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Metnin yüksekliğine eşit olan çerçeveyi boyutlandır
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Ebeveyn çerçeye ekleyin
textLabel.Parent = frame
end
-- Çerçeveleri bir listedeki düzenle (eğer henüz değilse)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end
FontFace
LineHeight
MaxVisibleGraphemes
MultiLine
OpenTypeFeatures
OpenTypeFeaturesError
PlaceholderColor3
PlaceholderText
RichText
SelectionStart
Kod Örnekleri
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
Text
Kod Örnekleri
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
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
local frame = script.Parent
-- Her bir fontu gösteren bir TextLabel oluştur
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Metin özelliklerini ayarla
textLabel.Text = font.Name
textLabel.Font = font
-- Bazı renderleme özellikleri
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Metnin yüksekliğine eşit olan çerçeveyi boyutlandır
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Ebeveyn çerçeye ekleyin
textLabel.Parent = frame
end
-- Çerçeveleri bir listedeki düzenle (eğer henüz değilse)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end
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
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
Kod Örnekleri
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
Kod Örnekleri
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)
-- 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)
-- 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
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- ReplicatedStorage'a "GameState" adlı bir StringValue yerleştir
local vGameState = ReplicatedStorage:WaitForChild("GameState")
-- Bu kodu bir TextLabel'e yerleştir
local textLabel = script.Parent
-- TextColor3 ile kullanacağımız bazı renkler
local colorNormal = Color3.new(0, 0, 0) -- sızık
local colorCountdown = Color3.new(1, 0.5, 0) -- turuncu
local colorRound = Color3.new(0.25, 0.25, 1) -- mavi
-- Bu işlevi çalıştıracağız TextLabel'i devlet olarak güncellemek için,
-- oyun değişiklikleri.
local function update()
-- Metni güncelle
textLabel.Text = "State: " .. vGameState.Value
-- Mevcut oyun durumuna göre metin rengini ayarlayın
if vGameState.Value == "Countdown" then
textLabel.TextColor3 = colorCountdown
elseif vGameState.Value == "Round" then
textLabel.TextColor3 = colorRound
else
textLabel.TextColor3 = colorNormal
end
end
-- Desen: başladığımızda ve vGameState değiştiğinde bir kez güncellenir
-- Her zaman en güncel GameState'i görmeliyiz.
update()
vGameState.Changed:Connect(update)
TextDirection
TextEditable
TextFits
TextScaled
Kod Örnekleri
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
Kod Örnekleri
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
Kod Örnekleri
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
Kod Örnekleri
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
Kod Örnekleri
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
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
TextWrapped
Kod Örnekleri
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
Kod Örnekleri
-- Bunu bir TextLabel/TextButton/TextBox içindeki YerelScript'e yapıştır
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
-- Hem TextXAlignment hem de TextYAlignment sayısal öğeler üzerinde döngü yap
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
Kod Örnekleri
-- Bunu bir TextLabel/TextButton/TextBox içindeki YerelScript'e yapıştır
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
-- Hem TextXAlignment hem de TextYAlignment sayısal öğeler üzerinde döngü yap
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
Yöntemler
CaptureFocus
Dönüşler
Kod Örnekleri
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)
ReleaseFocus
Parametreler
Dönüşler
Kod Örnekleri
local textBox = script.Parent
local function onFocused()
task.wait(5)
textBox:ReleaseFocus()
end
textBox.Focused:Connect(onFocused)
Olaylar
FocusLost
Parametreler
Kod Örnekleri
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)
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
Kod Örnekleri
local textBox = script.Parent
local function onFocused()
print("Focused")
end
textBox.Focused:Connect(onFocused)