Classe motore
GuiObject
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Proprietà
Metodi
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 |
Eventi
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 |
Membri ereditati
Membri ereditati da GuiBase2d: 12
Membri ereditati da Instance: 57
Membri ereditati da Object: 6
Ereditata da
Riferimento API
Proprietà
Active
Campioni di codice
TextButton Attivo Debounce
-- Inserisci questo LocalScript all'interno di un TextButton (o ImageButton)
local textButton = script.Parent
textButton.Text = "Cliccami"
textButton.Active = true
local function onActivated()
-- Questo agisce come un debounce
textButton.Active = false
-- Conta all'indietro da 5
for i = 5, 1, -1 do
textButton.Text = "Tempo: " .. i
task.wait(1)
end
textButton.Text = "Cliccami"
textButton.Active = true
end
textButton.Activated:Connect(onActivated)AnchorPoint
Campioni di codice
Dimostrazione AnchorPoint
local guiObject = script.Parent
while true do
-- In alto a sinistra
guiObject.AnchorPoint = Vector2.new(0, 0)
guiObject.Position = UDim2.new(0, 0, 0, 0)
task.wait(1)
-- In alto
guiObject.AnchorPoint = Vector2.new(0.5, 0)
guiObject.Position = UDim2.new(0.5, 0, 0, 0)
task.wait(1)
-- In alto a destra
guiObject.AnchorPoint = Vector2.new(1, 0)
guiObject.Position = UDim2.new(1, 0, 0, 0)
task.wait(1)
-- A sinistra
guiObject.AnchorPoint = Vector2.new(0, 0.5)
guiObject.Position = UDim2.new(0, 0, 0.5, 0)
task.wait(1)
-- Al centro
guiObject.AnchorPoint = Vector2.new(0.5, 0.5)
guiObject.Position = UDim2.new(0.5, 0, 0.5, 0)
task.wait(1)
-- A destra
guiObject.AnchorPoint = Vector2.new(1, 0.5)
guiObject.Position = UDim2.new(1, 0, 0.5, 0)
task.wait(1)
-- In basso a sinistra
guiObject.AnchorPoint = Vector2.new(0, 1)
guiObject.Position = UDim2.new(0, 0, 1, 0)
task.wait(1)
-- In basso
guiObject.AnchorPoint = Vector2.new(0.5, 1)
guiObject.Position = UDim2.new(0.5, 0, 1, 0)
task.wait(1)
-- In basso a destra
guiObject.AnchorPoint = Vector2.new(1, 1)
guiObject.Position = UDim2.new(1, 0, 1, 0)
task.wait(1)
endAutomaticSize
Campioni di codice
LocalScript in a ScreenGui
-- Array di etichette di testo/font/dimensioni da mostrare
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 },
}
-- Crea un frame genitore di dimensioni automatiche
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
-- Aggiungi un layout a lista
local listLayout = Instance.new("UIListLayout")
listLayout.Padding = UDim.new(0, 5)
listLayout.Parent = parentFrame
-- Imposta angoli arrotondati e padding per l'estetica visuale
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
-- Crea un'etichetta di testo di dimensioni automatiche dall'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
-- Estetica visiva
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
Campioni di codice
Cornice Arcobaleno
-- Inserisci questo codice in uno LocalScript in un Frame
local frame = script.Parent
while true do
for hue = 0, 255, 4 do
-- HSV = tonalità, saturazione, valore
-- Se cicliamo da 0 a 1 ripetutamente, otteniamo un arcobaleno!
frame.BorderColor3 = Color3.fromHSV(hue / 256, 1, 1)
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, 0.5, 0.8)
task.wait()
end
endBorderColor
BorderColor3
Campioni di codice
Evidenzia Bottone
-- Metti questo all'interno di un GuiObject, preferibilmente un ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Giallo
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Nero
end
-- Collega gli eventi
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Il nostro stato predefinito è "non evidenziato"
onLeave()BorderSizePixel
Campioni di codice
Evidenzia Bottone
-- Metti questo all'interno di un GuiObject, preferibilmente un ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Giallo
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Nero
end
-- Collega gli eventi
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Il nostro stato predefinito è "non evidenziato"
onLeave()Draggable
NextSelectionDown
Campioni di codice
Creare una Griglia di Selezione per Gamepad
-- Imposta la griglia di selezione del Gamepad utilizzando il codice qui sotto
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
-- Lato sinistro
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Lato destro
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Sopra
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Sotto
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Testa la griglia di selezione del Gamepad utilizzando il codice qui sotto
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
Campioni di codice
Creare una Griglia di Selezione per Gamepad
-- Imposta la griglia di selezione del Gamepad utilizzando il codice qui sotto
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
-- Lato sinistro
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Lato destro
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Sopra
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Sotto
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Testa la griglia di selezione del Gamepad utilizzando il codice qui sotto
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
Campioni di codice
Creare una Griglia di Selezione per Gamepad
-- Imposta la griglia di selezione del Gamepad utilizzando il codice qui sotto
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
-- Lato sinistro
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Lato destro
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Sopra
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Sotto
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Testa la griglia di selezione del Gamepad utilizzando il codice qui sotto
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
Campioni di codice
Creare una Griglia di Selezione per Gamepad
-- Imposta la griglia di selezione del Gamepad utilizzando il codice qui sotto
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
-- Lato sinistro
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Lato destro
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Sopra
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Sotto
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Testa la griglia di selezione del Gamepad utilizzando il codice qui sotto
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
Campioni di codice
Limitare la selezione della 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
-- L'evento FocusLost e FocusGained si attiverà perché la textBox
-- è di tipo TextBox
textBox.Focused:Connect(gainFocus)
textBox.FocusLost:Connect(loseFocus)Size
Campioni di codice
Barra della salute
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Incolla lo script in un LocalScript che è
-- genitore di un Frame all'interno di un Frame
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- nero
-- Questa funzione viene chiamata quando la salute dell'umanoide cambia
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Cambia la dimensione della barra interna
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Cambia il colore della barra della salute
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- rosso
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- giallo
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- verde
end
end
-- Questa funzione viene chiamata quando il giocatore appare
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Modello: aggiorna una volta ora, poi ogni volta che la salute cambia
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Collega il nostro ascoltatore di spawn; chiamalo se già apparso
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
endTransparency
Visible
Campioni di codice
Finestra UI
local gui = script.Parent
local window = gui:WaitForChild("Window")
local toggleButton = gui:WaitForChild("ToggleWindow")
local closeButton = window:WaitForChild("Close")
local function toggleWindowVisbility()
-- Inverte un booleano usando la parola chiave `not`
window.Visible = not window.Visible
end
toggleButton.Activated:Connect(toggleWindowVisbility)
closeButton.Activated:Connect(toggleWindowVisbility)Metodi
TweenPosition
TweenSize
TweenSizeAndPosition
Eventi
DragBegin
DragStopped
InputBegan
Parametri
Campioni di codice
Tracciare l'inizio dell'input su un GuiObject
-- Per utilizzare l'evento InputBegan, è necessario specificare il GuiObject
local gui = script.Parent
-- Una funzione di esempio che fornisce diversi casi d'uso per vari tipi di input dell'utente
local function inputBegan(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("Un tasto è stato premuto! Tasto:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Il pulsante sinistro del mouse è stato premuto in", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Il pulsante destro del mouse è stato premuto in", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("Un input touchscreen è iniziato in", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("Un pulsante è stato premuto su un gamepad! Pulsante:", input.KeyCode)
end
end
gui.InputBegan:Connect(inputBegan)InputChanged
Parametri
Campioni di codice
Esempio di InputChanged di GuiObject
local UserInputService = game:GetService("UserInputService")
local gui = script.Parent
local function printMovement(input)
print("Posizione:", input.Position)
print("Delta di Movimento:", input.Delta)
end
local function inputChanged(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
print("Il mouse è stato spostato!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
print("La rotellina del mouse è stata girata!")
print("Movimento della rotellina:", input.Position.Z)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.Thumbstick1 then
print("Il thumbstick sinistro è stato spostato!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
print("Il thumbstick destro è stato spostato!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
print("La pressione applicata al grilletto sinistro è cambiata!")
print("Pressione:", input.Position.Z)
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
print("La pressione applicata al grilletto destro è cambiata!")
print("Pressione:", input.Position.Z)
end
elseif input.UserInputType == Enum.UserInputType.Touch then
print("Il dito dell'utente si sta muovendo sullo schermo!")
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 rotazione del dispositivo mobile dell'utente è stata cambiata!")
print("Posizione", rotCFrame.p)
print("Rotazione:", rot)
elseif input.UserInputType == Enum.UserInputType.Accelerometer then
print("L'accelerazione del dispositivo mobile dell'utente è stata cambiata!")
printMovement(input)
end
end
gui.InputChanged:Connect(inputChanged)InputEnded
Parametri
Campioni di codice
Monitoraggio della fine dell'input su un GuiObject
-- Per utilizzare l'evento InputChanged, devi specificare un GuiObject
local gui = script.Parent
-- Una funzione di esempio che fornisce più casi d'uso per vari tipi di input utente
local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("Un tasto è stato rilasciato! Tasto:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Il pulsante sinistro del mouse è stato rilasciato a", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Il pulsante destro del mouse è stato rilasciato a", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("Un input touchscreen è stato rilasciato a", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("Un pulsante è stato rilasciato su un gamepad! Pulsante:", input.KeyCode)
end
end
gui.InputEnded:Connect(inputEnded)MouseEnter
Campioni di codice
Stampa quando un Mouse Entra in un GuiObject
local guiObject = script.Parent
guiObject.MouseEnter:Connect(function(x, y)
print("Il cursore del mouse dell'utente è entrato nel GuiObject alla posizione", x, ",", y)
end)MouseWheelBackward
MouseWheelForward
SelectionGained
Campioni di codice
Gestione della selezione GUI acquisita
local guiObject = script.Parent
local function selectionGained()
print("L'utente ha selezionato questo pulsante con un gamepad.")
end
guiObject.SelectionGained:Connect(selectionGained)SelectionLost
Campioni di codice
Gestione della perdita di selezione GUI
local guiObject = script.Parent
local function selectionLost()
print("L'utente non ha più questa selezione con il loro gamepad.")
end
guiObject.SelectionLost:Connect(selectionLost)TouchLongPress
Parametri
Campioni di codice
Sposta Elemento UI con TouchLongPress
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
-- Inizia un trascinamento
dragging = true
basePosition = frame.Position
startTouchPosition = touchPositions[1]
-- Colora il frame per indicare che il trascinamento sta avvenendo
borderColor3 = frame.BorderColor3
backgroundColor3 = frame.BackgroundColor3
frame.BorderColor3 = Color3.new(1, 1, 1) -- Bianco
frame.BackgroundColor3 = Color3.new(0, 0, 1) -- Blu
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
-- Ferma il trascinamento
dragging = false
frame.BorderColor3 = borderColor3
frame.BackgroundColor3 = backgroundColor3
end
end
frame.TouchLongPress:Connect(onTouchLongPress)TouchPan
GuiObject.TouchPan(
Parametri
Campioni di codice
Elemento UI Scorrevole
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(
Parametri
Campioni di codice
Scala di pizzico/tirare
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 -- Nota la moltiplicazione qui
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPinch:Connect(onTouchPinch)TouchRotate
GuiObject.TouchRotate(
Parametri
Campioni di codice
Rotazione al Tocco
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
Parametri
Campioni di codice
Selettore di Colore Rimbalzante
local frame = script.Parent
frame.Active = true
-- Quanto lontano il frame dovrebbe rimbalzare in caso di scorrimento riuscito
local BOUNCE_DISTANCE = 50
-- Stato attuale del 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)
-- Cambia il BackgroundColor3 in base alla direzione dello scorrimento
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
-- Aggiorna il colore e fa rimbalzare un po' il frame
updateColor()
frame.Position = basePosition + deltaPos
frame:TweenPosition(basePosition, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 0.7, true)
end
frame.TouchSwipe:Connect(onTouchSwipe)
updateColor()TouchTap
Parametri
Campioni di codice
Attiva/disattiva trasparenza
local frame = script.Parent
frame.Active = true
local function onTouchTap()
-- Attiva/disattiva la trasparenza dello sfondo
if frame.BackgroundTransparency > 0 then
frame.BackgroundTransparency = 0
else
frame.BackgroundTransparency = 0.75
end
end
frame.TouchTap:Connect(onTouchTap)