Classe do mecanismo
GuiObject
*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.
Resumo
Propriedades
Métodos
TweenPosition(endPosition: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean |
TweenSize(endSize: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean |
TweenSizeAndPosition(endSize: UDim2,endPosition: UDim2,easingDirection: Enum.EasingDirection,easingStyle: Enum.EasingStyle,time: number,override: boolean,callback: function):boolean |
Eventos
DragBegin(initialPosition: UDim2):RBXScriptSignal |
DragStopped(x: number,y: number):RBXScriptSignal |
InputBegan(input: InputObject):RBXScriptSignal |
InputChanged(input: InputObject):RBXScriptSignal |
InputEnded(input: InputObject):RBXScriptSignal |
MouseEnter(x: number,y: number):RBXScriptSignal |
MouseLeave(x: number,y: number):RBXScriptSignal |
MouseMoved(x: number,y: number):RBXScriptSignal |
TouchLongPress(touchPositions: {any},state: Enum.UserInputState):RBXScriptSignal |
TouchPan(touchPositions: {any},totalTranslation: Vector2,velocity: Vector2,state: Enum.UserInputState):RBXScriptSignal |
TouchPinch(touchPositions: {any},scale: number,velocity: number,state: Enum.UserInputState):RBXScriptSignal |
TouchRotate(touchPositions: {any},rotation: number,velocity: number,state: Enum.UserInputState):RBXScriptSignal |
TouchSwipe(swipeDirection: Enum.SwipeDirection,numberOfTouches: number):RBXScriptSignal |
TouchTap(touchPositions: {any}):RBXScriptSignal |
Herdado por
Referência API
Propriedades
Active
Amostras de código
Botão de Texto Ativo Debounce
-- Coloque este LocalScript dentro de um TextButton (ou ImageButton)
local textButton = script.Parent
textButton.Text = "Clique em mim"
textButton.Active = true
local function onActivated()
-- Isso funciona como um debounce
textButton.Active = false
-- Contar regressivamente de 5
for i = 5, 1, -1 do
textButton.Text = "Tempo: " .. i
task.wait(1)
end
textButton.Text = "Clique em mim"
textButton.Active = true
end
textButton.Activated:Connect(onActivated)AnchorPoint
Amostras de código
Demonstração do AnchorPoint
local guiObject = script.Parent
while true do
-- Canto superior esquerdo
guiObject.AnchorPoint = Vector2.new(0, 0)
guiObject.Position = UDim2.new(0, 0, 0, 0)
task.wait(1)
-- Cima
guiObject.AnchorPoint = Vector2.new(0.5, 0)
guiObject.Position = UDim2.new(0.5, 0, 0, 0)
task.wait(1)
-- Canto superior direito
guiObject.AnchorPoint = Vector2.new(1, 0)
guiObject.Position = UDim2.new(1, 0, 0, 0)
task.wait(1)
-- Esquerda
guiObject.AnchorPoint = Vector2.new(0, 0.5)
guiObject.Position = UDim2.new(0, 0, 0.5, 0)
task.wait(1)
-- Centro morto
guiObject.AnchorPoint = Vector2.new(0.5, 0.5)
guiObject.Position = UDim2.new(0.5, 0, 0.5, 0)
task.wait(1)
-- Direita
guiObject.AnchorPoint = Vector2.new(1, 0.5)
guiObject.Position = UDim2.new(1, 0, 0.5, 0)
task.wait(1)
-- Canto inferior esquerdo
guiObject.AnchorPoint = Vector2.new(0, 1)
guiObject.Position = UDim2.new(0, 0, 1, 0)
task.wait(1)
-- Embaixo
guiObject.AnchorPoint = Vector2.new(0.5, 1)
guiObject.Position = UDim2.new(0.5, 0, 1, 0)
task.wait(1)
-- Canto inferior direito
guiObject.AnchorPoint = Vector2.new(1, 1)
guiObject.Position = UDim2.new(1, 0, 1, 0)
task.wait(1)
endAutomaticSize
Amostras de código
LocalScript em um ScreenGui
-- Array de rótulos de texto/fontes/tamanhos para saída
local labelArray = {
{ text = "Lorem", font = Enum.Font.Creepster, size = 50 },
{ text = "ipsum", font = Enum.Font.IndieFlower, size = 35 },
{ text = "dolor", font = Enum.Font.Antique, size = 55 },
{ text = "sit", font = Enum.Font.SpecialElite, size = 65 },
{ text = "amet", font = Enum.Font.FredokaOne, size = 40 },
}
-- Crie um quadro pai com tamanho automático
local parentFrame = Instance.new("Frame")
parentFrame.AutomaticSize = Enum.AutomaticSize.XY
parentFrame.BackgroundColor3 = Color3.fromRGB(90, 90, 90)
parentFrame.Size = UDim2.fromOffset(25, 100)
parentFrame.Position = UDim2.fromScale(0.1, 0.1)
parentFrame.Parent = script.Parent
-- Adicione um layout de lista
local listLayout = Instance.new("UIListLayout")
listLayout.Padding = UDim.new(0, 5)
listLayout.Parent = parentFrame
-- Defina cantos arredondados e preenchimento para estética visual
local roundedCornerParent = Instance.new("UICorner")
roundedCornerParent.Parent = parentFrame
local uiPaddingParent = Instance.new("UIPadding")
uiPaddingParent.PaddingTop = UDim.new(0, 5)
uiPaddingParent.PaddingLeft = UDim.new(0, 5)
uiPaddingParent.PaddingRight = UDim.new(0, 5)
uiPaddingParent.PaddingBottom = UDim.new(0, 5)
uiPaddingParent.Parent = parentFrame
for i = 1, #labelArray do
-- Crie um rótulo de texto com tamanho automático a partir do array
local childLabel = Instance.new("TextLabel")
childLabel.AutomaticSize = Enum.AutomaticSize.XY
childLabel.Size = UDim2.fromOffset(75, 15)
childLabel.Text = labelArray[i]["text"]
childLabel.Font = labelArray[i]["font"]
childLabel.TextSize = labelArray[i]["size"]
childLabel.TextColor3 = Color3.new(1, 1, 1)
childLabel.Parent = parentFrame
-- Estética visual
local roundedCorner = Instance.new("UICorner")
roundedCorner.Parent = childLabel
local uiPadding = Instance.new("UIPadding")
uiPadding.PaddingTop = UDim.new(0, 5)
uiPadding.PaddingLeft = UDim.new(0, 5)
uiPadding.PaddingRight = UDim.new(0, 5)
uiPadding.PaddingBottom = UDim.new(0, 5)
uiPadding.Parent = childLabel
task.wait(2)
endBackgroundColor
BackgroundColor3
Amostras de código
Quadro Arco-Íris
-- Coloque este código em um LocalScript em um Frame
local frame = script.Parent
while true do
for hue = 0, 255, 4 do
-- HSV = matiz, saturação, valor
-- Se fizermos um loop de 0 a 1 repetidamente, teremos um arco-íris!
frame.BorderColor3 = Color3.fromHSV(hue / 256, 1, 1)
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, 0.5, 0.8)
task.wait()
end
endBorderColor
BorderColor3
Amostras de código
Destaque do Botão
-- Coloque-me dentro de algum GuiObject, de preferência um ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Amarelo
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Preto
end
-- Conectar eventos
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Nosso estado padrão é "não sobreposto"
onLeave()BorderSizePixel
Amostras de código
Destaque do Botão
-- Coloque-me dentro de algum GuiObject, de preferência um ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Amarelo
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Preto
end
-- Conectar eventos
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Nosso estado padrão é "não sobreposto"
onLeave()Draggable
NextSelectionDown
Amostras de código
Criando uma Grade de Seleção de Gamepad
-- Configura a grade de seleção de Gamepad usando o código abaixo
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Borda esquerda
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Borda direita
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Acima
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Abaixo
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Testa a grade de seleção de Gamepad usando o código abaixo
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)NextSelectionLeft
Amostras de código
Criando uma Grade de Seleção de Gamepad
-- Configura a grade de seleção de Gamepad usando o código abaixo
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Borda esquerda
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Borda direita
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Acima
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Abaixo
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Testa a grade de seleção de Gamepad usando o código abaixo
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)NextSelectionRight
Amostras de código
Criando uma Grade de Seleção de Gamepad
-- Configura a grade de seleção de Gamepad usando o código abaixo
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Borda esquerda
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Borda direita
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Acima
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Abaixo
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Testa a grade de seleção de Gamepad usando o código abaixo
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)NextSelectionUp
Amostras de código
Criando uma Grade de Seleção de Gamepad
-- Configura a grade de seleção de Gamepad usando o código abaixo
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Borda esquerda
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Borda direita
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Acima
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Abaixo
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Testa a grade de seleção de Gamepad usando o código abaixo
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)Selectable
Amostras de código
Limitando a Seleção do TextBox
local GuiService = game:GetService("GuiService")
local textBox = script.Parent
local function gainFocus()
textBox.Selectable = true
GuiService.SelectedObject = textBox
end
local function loseFocus(_enterPressed, _inputObject)
GuiService.SelectedObject = nil
textBox.Selectable = false
end
-- O evento FocusLost e FocusGained será disparado porque o textBox
-- é do tipo TextBox
textBox.Focused:Connect(gainFocus)
textBox.FocusLost:Connect(loseFocus)Size
Amostras de código
Barra de Saúde
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Cole o script em um LocalScript que esteja
-- posicionado dentro de um Frame dentro de um Frame
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- preto
-- Esta função é chamada quando a saúde do humanoide muda
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Mude o tamanho da barra interna
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Mude a cor da barra de saúde
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- vermelho
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- amarelo
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- verde
end
end
-- Esta função é chamada quando o jogador renasce
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Padrão: atualize uma vez agora, depois sempre que a saúde mudar
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Conecte nosso ouvinte de renascimento; chame se já tiver renascido
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
endTransparency
Visible
Amostras de código
Janela de UI
local gui = script.Parent
local window = gui:WaitForChild("Window")
local toggleButton = gui:WaitForChild("ToggleWindow")
local closeButton = window:WaitForChild("Close")
local function toggleWindowVisbility()
-- Inverte um booleano usando a palavra-chave `not`
window.Visible = not window.Visible
end
toggleButton.Activated:Connect(toggleWindowVisbility)
closeButton.Activated:Connect(toggleWindowVisbility)Métodos
TweenPosition
TweenSize
TweenSizeAndPosition
Eventos
DragBegin
DragStopped
InputBegan
Parâmetros
Amostras de código
Rastreando o Início da Entrada em um GuiObject
-- Para usar o evento InputBegan, você deve especificar o GuiObject
local gui = script.Parent
-- Uma função de exemplo fornecendo múltiplos casos de uso para vários tipos de entrada do usuário
local function inputBegan(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("Uma tecla está sendo pressionada! Tecla:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("O botão esquerdo do mouse foi pressionado em", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("O botão direito do mouse foi pressionado em", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("Uma entrada de tela sensível ao toque começou em", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("Um botão está sendo pressionado em um gamepad! Botão:", input.KeyCode)
end
end
gui.InputBegan:Connect(inputBegan)InputChanged
Parâmetros
Amostras de código
Demonstração de InputChanged de GuiObject
local UserInputService = game:GetService("UserInputService")
local gui = script.Parent
local function printMovement(input)
print("Posição:", input.Position)
print("Delta de Movimento:", input.Delta)
end
local function inputChanged(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
print("O mouse foi movido!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
print("A roda do mouse foi rolada!")
print("Movimento da Roda:", input.Position.Z)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.Thumbstick1 then
print("O thumbstick esquerdo foi movido!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
print("O thumbstick direito foi movido!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
print("A pressão aplicada ao gatilho esquerdo foi alterada!")
print("Pressão:", input.Position.Z)
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
print("A pressão aplicada ao gatilho direito foi alterada!")
print("Pressão:", input.Position.Z)
end
elseif input.UserInputType == Enum.UserInputType.Touch then
print("O dedo do usuário está se movendo na tela!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.Gyro then
local _rotInput, rotCFrame = UserInputService:GetDeviceRotation()
local rotX, rotY, rotZ = rotCFrame:toEulerAnglesXYZ()
local rot = Vector3.new(math.deg(rotX), math.deg(rotY), math.deg(rotZ))
print("A rotação do dispositivo móvel do usuário foi alterada!")
print("Posição", rotCFrame.p)
print("Rotação:", rot)
elseif input.UserInputType == Enum.UserInputType.Accelerometer then
print("A aceleração do dispositivo móvel do usuário foi alterada!")
printMovement(input)
end
end
gui.InputChanged:Connect(inputChanged)InputEnded
Parâmetros
Amostras de código
Rastreando o Fim da Entrada em um GuiObject
-- Para usar o evento InputChanged, você deve especificar um GuiObject
local gui = script.Parent
-- Uma função de exemplo fornecendo vários casos de uso para diversos tipos de entrada de usuário
local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("Uma tecla foi liberada! Tecla:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("O botão esquerdo do mouse foi liberado em", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("O botão direito do mouse foi liberado em", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("Uma entrada de tela sensível ao toque foi liberada em", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("Um botão foi liberado em um gamepad! Botão:", input.KeyCode)
end
end
gui.InputEnded:Connect(inputEnded)MouseEnter
Amostras de código
Imprimindo onde um Mouse Entra em um GuiObject
local guiObject = script.Parent
guiObject.MouseEnter:Connect(function(x, y)
print("O cursor do mouse do usuário entrou no GuiObject na posição", x, ",", y)
end)MouseWheelBackward
MouseWheelForward
SelectionGained
Amostras de código
Manipulação da Seleção de GUI Obtida
local guiObject = script.Parent
local function selectionGained()
print("O usuário selecionou este botão com um gamepad.")
end
guiObject.SelectionGained:Connect(selectionGained)SelectionLost
Amostras de código
Perdendo a Seleção da GUI
local guiObject = script.Parent
local function selectionLost()
print("O usuário não tem mais isso selecionado com seu controle.")
end
guiObject.SelectionLost:Connect(selectionLost)TouchLongPress
Parâmetros
Amostras de código
Mover Elemento UI com Toque Longo
local frame = script.Parent
frame.Active = true
local dragging = false
local basePosition
local startTouchPosition
local borderColor3
local backgroundColor3
local function onTouchLongPress(touchPositions, state)
if state == Enum.UserInputState.Begin and not dragging then
-- Iniciar um arraste
dragging = true
basePosition = frame.Position
startTouchPosition = touchPositions[1]
-- Colorir o frame para indicar que o arraste está acontecendo
borderColor3 = frame.BorderColor3
backgroundColor3 = frame.BackgroundColor3
frame.BorderColor3 = Color3.new(1, 1, 1) -- Branco
frame.BackgroundColor3 = Color3.new(0, 0, 1) -- Azul
elseif state == Enum.UserInputState.Change then
local touchPosition = touchPositions[1]
local deltaPosition =
UDim2.new(0, touchPosition.X - startTouchPosition.X, 0, touchPosition.Y - startTouchPosition.Y)
frame.Position = basePosition + deltaPosition
elseif state == Enum.UserInputState.End and dragging then
-- Parar o arraste
dragging = false
frame.BorderColor3 = borderColor3
frame.BackgroundColor3 = backgroundColor3
end
end
frame.TouchLongPress:Connect(onTouchLongPress)TouchPan
GuiObject.TouchPan(
Parâmetros
Amostras de código
Elemento de UI com Panning
local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local basePosition
local function onTouchPan(_touchPositions, totalTranslation, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
basePosition = innerFrame.Position
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
innerFrame.Position = basePosition + UDim2.new(0, totalTranslation.X, 0, totalTranslation.Y)
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPan:Connect(onTouchPan)TouchPinch
GuiObject.TouchPinch(
Parâmetros
Amostras de código
Escalonamento de Pinça/Pull
local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local uiScale = Instance.new("UIScale")
uiScale.Parent = innerFrame
local baseScale
local function onTouchPinch(_touchPositions, scale, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
baseScale = uiScale.Scale
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
uiScale.Scale = baseScale * scale -- Observe a multiplicação aqui
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPinch:Connect(onTouchPinch)TouchRotate
GuiObject.TouchRotate(
Parâmetros
Amostras de código
Rotação por Toque
local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local baseRotation = innerFrame.Rotation
local function onTouchRotate(_touchPositions, rotation, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
baseRotation = innerFrame.Rotation
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
innerFrame.Rotation = baseRotation + rotation
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchRotate:Connect(onTouchRotate)TouchSwipe
Parâmetros
Amostras de código
Seletor de Cor Bouncing
local frame = script.Parent
frame.Active = true
-- Quão longe o frame deve pular em um deslizar bem-sucedido
local BOUNCE_DISTANCE = 50
-- Estado atual do frame
local basePosition = frame.Position
local hue = 0
local saturation = 128
local function updateColor()
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, saturation / 256, 1)
end
local function onTouchSwipe(swipeDir, _touchCount)
-- Mudar o BackgroundColor3 com base na direção do deslizar
local deltaPos
if swipeDir == Enum.SwipeDirection.Right then
deltaPos = UDim2.new(0, BOUNCE_DISTANCE, 0, 0)
hue = (hue + 16) % 255
elseif swipeDir == Enum.SwipeDirection.Left then
deltaPos = UDim2.new(0, -BOUNCE_DISTANCE, 0, 0)
hue = (hue - 16) % 255
elseif swipeDir == Enum.SwipeDirection.Up then
deltaPos = UDim2.new(0, 0, 0, -BOUNCE_DISTANCE)
saturation = (saturation + 16) % 255
elseif swipeDir == Enum.SwipeDirection.Down then
deltaPos = UDim2.new(0, 0, 0, BOUNCE_DISTANCE)
saturation = (saturation - 16) % 255
else
deltaPos = UDim2.new()
end
-- Atualizar a cor e fazer o frame pular um pouco
updateColor()
frame.Position = basePosition + deltaPos
frame:TweenPosition(basePosition, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 0.7, true)
end
frame.TouchSwipe:Connect(onTouchSwipe)
updateColor()TouchTap
Parâmetros
Amostras de código
Alternar Transparência
local frame = script.Parent
frame.Active = true
local function onTouchTap()
-- Alternar transparência de fundo
if frame.BackgroundTransparency > 0 then
frame.BackgroundTransparency = 0
else
frame.BackgroundTransparency = 0.75
end
end
frame.TouchTap:Connect(onTouchTap)