Clase de motor
GuiObject
*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.
Resumen
Propiedades
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
Heredado por
Referencia API
Propiedades
Active
Muestras de código
Botón de Texto Activo Debounce
-- Coloca este LocalScript dentro de un TextButton (o ImageButton)
local textButton = script.Parent
textButton.Text = "Haz clic en mí"
textButton.Active = true
local function onActivated()
-- Esto actúa como un debounce
textButton.Active = false
-- Cuenta hacia atrás desde 5
for i = 5, 1, -1 do
textButton.Text = "Tiempo: " .. i
task.wait(1)
end
textButton.Text = "Haz clic en mí"
textButton.Active = true
end
textButton.Activated:Connect(onActivated)AnchorPoint
Muestras de código
Demostración del punto de anclaje
local guiObject = script.Parent
while true do
-- Parte superior izquierda
guiObject.AnchorPoint = Vector2.new(0, 0)
guiObject.Position = UDim2.new(0, 0, 0, 0)
task.wait(1)
-- Parte superior
guiObject.AnchorPoint = Vector2.new(0.5, 0)
guiObject.Position = UDim2.new(0.5, 0, 0, 0)
task.wait(1)
-- Parte superior derecha
guiObject.AnchorPoint = Vector2.new(1, 0)
guiObject.Position = UDim2.new(1, 0, 0, 0)
task.wait(1)
-- Izquierda
guiObject.AnchorPoint = Vector2.new(0, 0.5)
guiObject.Position = UDim2.new(0, 0, 0.5, 0)
task.wait(1)
-- Centro exacto
guiObject.AnchorPoint = Vector2.new(0.5, 0.5)
guiObject.Position = UDim2.new(0.5, 0, 0.5, 0)
task.wait(1)
-- Derecha
guiObject.AnchorPoint = Vector2.new(1, 0.5)
guiObject.Position = UDim2.new(1, 0, 0.5, 0)
task.wait(1)
-- Parte inferior izquierda
guiObject.AnchorPoint = Vector2.new(0, 1)
guiObject.Position = UDim2.new(0, 0, 1, 0)
task.wait(1)
-- Parte inferior
guiObject.AnchorPoint = Vector2.new(0.5, 1)
guiObject.Position = UDim2.new(0.5, 0, 1, 0)
task.wait(1)
-- Parte inferior derecha
guiObject.AnchorPoint = Vector2.new(1, 1)
guiObject.Position = UDim2.new(1, 0, 1, 0)
task.wait(1)
endAutomaticSize
Muestras de código
LocalScript en un ScreenGui
-- Array de etiquetas de texto/fuentes/tamaños a mostrar
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 },
}
-- Crear un marco padre de tamaño 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
-- Añadir un diseño de lista
local listLayout = Instance.new("UIListLayout")
listLayout.Padding = UDim.new(0, 5)
listLayout.Parent = parentFrame
-- Establecer bordes redondeados y relleno 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
-- Crear una etiqueta de texto de tamaño automático desde el 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
Muestras de código
Marco Iris
-- Pon este código en un LocalScript en un Frame
local frame = script.Parent
while true do
for hue = 0, 255, 4 do
-- HSV = tono, saturación, valor
-- Si recorremos de 0 a 1 repetidamente, ¡obtenemos un 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
Muestras de código
Resaltar Botón
-- Colócame dentro de algún GuiObject, preferiblemente un ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Amarillo
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Negro
end
-- Conectar eventos
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Nuestro estado por defecto es "no resaltado"
onLeave()BorderSizePixel
Muestras de código
Resaltar Botón
-- Colócame dentro de algún GuiObject, preferiblemente un ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Amarillo
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Negro
end
-- Conectar eventos
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Nuestro estado por defecto es "no resaltado"
onLeave()Draggable
NextSelectionDown
Muestras de código
Creando una cuadrícula de selección de gamepad
-- Configura la cuadrícula de selección del gamepad utilizando el código a continuación
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
-- Borde izquierdo
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Borde derecho
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Arriba
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Abajo
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Prueba la cuadrícula de selección del gamepad utilizando el código a continuación
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
Muestras de código
Creando una cuadrícula de selección de gamepad
-- Configura la cuadrícula de selección del gamepad utilizando el código a continuación
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
-- Borde izquierdo
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Borde derecho
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Arriba
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Abajo
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Prueba la cuadrícula de selección del gamepad utilizando el código a continuación
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
Muestras de código
Creando una cuadrícula de selección de gamepad
-- Configura la cuadrícula de selección del gamepad utilizando el código a continuación
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
-- Borde izquierdo
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Borde derecho
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Arriba
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Abajo
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Prueba la cuadrícula de selección del gamepad utilizando el código a continuación
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
Muestras de código
Creando una cuadrícula de selección de gamepad
-- Configura la cuadrícula de selección del gamepad utilizando el código a continuación
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
-- Borde izquierdo
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Borde derecho
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Arriba
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Abajo
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Prueba la cuadrícula de selección del gamepad utilizando el código a continuación
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
Muestras de código
Limitación de Selección de 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
-- El evento FocusLost y FocusGained se activará porque el textBox
-- es del tipo TextBox
textBox.Focused:Connect(gainFocus)
textBox.FocusLost:Connect(loseFocus)Size
Muestras de código
Barras de Salud
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Pega el script en un LocalScript que esté
-- parentado a un Frame dentro de un Frame
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- negro
-- Esta función se llama cuando la salud del humanoide cambia
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Cambia el tamaño de la barra interior
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Cambia el color de la barra de salud
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- rojo
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- amarillo
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- verde
end
end
-- Esta función se llama cuando el jugador aparece
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Patrón: actualizar una vez ahora, luego cada vez que cambie la salud
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Conectar nuestro oyente de aparición; llamarlo si ya ha aparecido
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
endTransparency
Visible
Muestras de código
Ventana de UI
local gui = script.Parent
local window = gui:WaitForChild("Window")
local toggleButton = gui:WaitForChild("ToggleWindow")
local closeButton = window:WaitForChild("Close")
local function toggleWindowVisbility()
-- Cambia un booleano usando la palabra clave `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
Muestras de código
Seguimiento del Comienzo de la Entrada en un GuiObject
-- Para usar el evento InputBegan, debes especificar el GuiObject
local gui = script.Parent
-- Una función de muestra que proporciona múltiples casos de uso para varios tipos de entrada del usuario
local function inputBegan(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("¡Una tecla está siendo presionada! Tecla:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("¡El botón izquierdo del mouse ha sido presionado en", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("¡El botón derecho del mouse ha sido presionado en", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("¡Una entrada de pantalla táctil ha comenzado en", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("¡Un botón está siendo presionado en un gamepad! Botón:", input.KeyCode)
end
end
gui.InputBegan:Connect(inputBegan)InputChanged
Parámetros
Muestras de código
Demo de InputChanged de GuiObject
local UserInputService = game:GetService("UserInputService")
local gui = script.Parent
local function printMovement(input)
print("Posición:", input.Position)
print("Delta de Movimiento:", input.Delta)
end
local function inputChanged(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
print("¡El mouse se ha movido!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
print("¡La rueda del mouse ha sido desplazada!")
print("Movimiento de Rueda:", input.Position.Z)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.Thumbstick1 then
print("¡El thumbstick izquierdo se ha movido!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
print("¡El thumbstick derecho se ha movido!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
print("¡La presión aplicada al gatillo izquierdo ha cambiado!")
print("Presión:", input.Position.Z)
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
print("¡La presión aplicada al gatillo derecho ha cambiado!")
print("Presión:", input.Position.Z)
end
elseif input.UserInputType == Enum.UserInputType.Touch then
print("¡El dedo del usuario está moviéndose en la pantalla!")
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("¡La rotación del dispositivo móvil del usuario ha cambiado!")
print("Posición", rotCFrame.p)
print("Rotación:", rot)
elseif input.UserInputType == Enum.UserInputType.Accelerometer then
print("¡La aceleración del dispositivo móvil del usuario ha cambiado!")
printMovement(input)
end
end
gui.InputChanged:Connect(inputChanged)InputEnded
Parámetros
Muestras de código
Rastreando el Fin de la Entrada en un GuiObject
-- Para utilizar el evento InputChanged, debes especificar un GuiObject
local gui = script.Parent
-- Una función de ejemplo que proporciona múltiples casos de uso para varios tipos de entrada del usuario
local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("¡Se ha soltado una tecla! Tecla:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("¡Se ha soltado el botón izquierdo del mouse en", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("¡Se ha soltado el botón derecho del mouse en", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("¡Se ha soltado una entrada táctil en", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("¡Se ha soltado un botón en un gamepad! Botón:", input.KeyCode)
end
end
gui.InputEnded:Connect(inputEnded)MouseEnter
Muestras de código
Imprimiendo dónde un Mouse Entra en un GuiObject
local guiObject = script.Parent
guiObject.MouseEnter:Connect(function(x, y)
print("El cursor del mouse del usuario ha entrado en el GuiObject en la posición", x, ",", y)
end)MouseWheelBackward
MouseWheelForward
SelectionGained
Parámetros
Muestras de código
Manejo de Selección de GUI Ganada
local guiObject = script.Parent
local function selectionGained()
print("El usuario ha seleccionado este botón con un gamepad.")
end
guiObject.SelectionGained:Connect(selectionGained)SelectionLost
Parámetros
Muestras de código
Manejo de la selección de GUI perdida
local guiObject = script.Parent
local function selectionLost()
print("El usuario ya no tiene esto seleccionado con su gamepad.")
end
guiObject.SelectionLost:Connect(selectionLost)TouchLongPress
Parámetros
Muestras de código
Mover Elemento UI con Toque Larga Presión
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
-- Comenzar a arrastrar
dragging = true
basePosition = frame.Position
startTouchPosition = touchPositions[1]
-- Colorear el marco para indicar que el arrastre está sucediendo
borderColor3 = frame.BorderColor3
backgroundColor3 = frame.BackgroundColor3
frame.BorderColor3 = Color3.new(1, 1, 1) -- Blanco
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
-- Detener el arrastre
dragging = false
frame.BorderColor3 = borderColor3
frame.BackgroundColor3 = backgroundColor3
end
end
frame.TouchLongPress:Connect(onTouchLongPress)TouchPan
GuiObject.TouchPan(
Parámetros
Muestras de código
Elemento de interfaz de usuario de desplazamiento
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
Muestras de código
Escalado de Pinch/Jalar
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 -- Notar la multiplicación aquí
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
Muestras de código
Rotación Táctil
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
Muestras de código
Seleccionador de Color Rebotante
local frame = script.Parent
frame.Active = true
-- Cuánto debe rebotar el marco en un deslizamiento exitoso
local BOUNCE_DISTANCE = 50
-- Estado actual del marco
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)
-- Cambiar el BackgroundColor3 basado en la dirección del deslizamiento
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
-- Actualizar el color y hacer rebotar el marco un poco
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
Muestras de código
Alternar la Transparencia
local frame = script.Parent
frame.Active = true
local function onTouchTap()
-- Alternar la transparencia del fondo
if frame.BackgroundTransparency > 0 then
frame.BackgroundTransparency = 0
else
frame.BackgroundTransparency = 0.75
end
end
frame.TouchTap:Connect(onTouchTap)