요약
속성
메서드
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 |
이벤트
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 |
상속된 멤버
상속자
API 참조
속성
Active
코드 샘플
텍스트 버튼 활성 디바운스
-- 이 LocalScript를 TextButton (또는 ImageButton) 안에 배치하세요
local textButton = script.Parent
textButton.Text = "클릭하세요"
textButton.Active = true
local function onActivated()
-- 이것은 디바운스처럼 작용합니다
textButton.Active = false
-- 5부터 거꾸로 세기
for i = 5, 1, -1 do
textButton.Text = "시간: " .. i
task.wait(1)
end
textButton.Text = "클릭하세요"
textButton.Active = true
end
textButton.Activated:Connect(onActivated)AnchorPoint
코드 샘플
앵커 포인트 데모
local guiObject = script.Parent
while true do
-- 왼쪽 상단
guiObject.AnchorPoint = Vector2.new(0, 0)
guiObject.Position = UDim2.new(0, 0, 0, 0)
task.wait(1)
-- 상단
guiObject.AnchorPoint = Vector2.new(0.5, 0)
guiObject.Position = UDim2.new(0.5, 0, 0, 0)
task.wait(1)
-- 오른쪽 상단
guiObject.AnchorPoint = Vector2.new(1, 0)
guiObject.Position = UDim2.new(1, 0, 0, 0)
task.wait(1)
-- 왼쪽
guiObject.AnchorPoint = Vector2.new(0, 0.5)
guiObject.Position = UDim2.new(0, 0, 0.5, 0)
task.wait(1)
-- 정 중앙
guiObject.AnchorPoint = Vector2.new(0.5, 0.5)
guiObject.Position = UDim2.new(0.5, 0, 0.5, 0)
task.wait(1)
-- 오른쪽
guiObject.AnchorPoint = Vector2.new(1, 0.5)
guiObject.Position = UDim2.new(1, 0, 0.5, 0)
task.wait(1)
-- 왼쪽 하단
guiObject.AnchorPoint = Vector2.new(0, 1)
guiObject.Position = UDim2.new(0, 0, 1, 0)
task.wait(1)
-- 하단
guiObject.AnchorPoint = Vector2.new(0.5, 1)
guiObject.Position = UDim2.new(0.5, 0, 1, 0)
task.wait(1)
-- 오른쪽 하단
guiObject.AnchorPoint = Vector2.new(1, 1)
guiObject.Position = UDim2.new(1, 0, 1, 0)
task.wait(1)
endAutomaticSize
코드 샘플
ScreenGui의 LocalScript
-- 출력할 텍스트 레이블/폰트/크기 배열
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 },
}
-- 자동 크기 조정되는 부모 프레임 생성
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
-- 리스트 레이아웃 추가
local listLayout = Instance.new("UIListLayout")
listLayout.Padding = UDim.new(0, 5)
listLayout.Parent = parentFrame
-- 시각적 미학을 위한 둥근 모서리 및 패딩 설정
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
-- 배열에서 자동 크기 조정되는 텍스트 레이블 생성
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
-- 시각적 미학
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
코드 샘플
무지개 프레임
-- 이 코드를 프레임의 LocalScript에 넣으세요
local frame = script.Parent
while true do
for hue = 0, 255, 4 do
-- HSV = 색상, 채도, 명도
-- 0에서 1까지 반복적으로 순환하면 무지개를 얻습니다!
frame.BorderColor3 = Color3.fromHSV(hue / 256, 1, 1)
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, 0.5, 0.8)
task.wait()
end
endBorderColor
BorderColor3
코드 샘플
버튼 강조
-- GuiObject 안에 넣어주세요. 가능한 한 ImageButton/TextButton이 좋습니다.
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- 노란색
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- 검은색
end
-- 이벤트 연결
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- 기본 상태는 "호버되지 않음"입니다.
onLeave()BorderSizePixel
코드 샘플
버튼 강조
-- GuiObject 안에 넣어주세요. 가능한 한 ImageButton/TextButton이 좋습니다.
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- 노란색
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- 검은색
end
-- 이벤트 연결
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- 기본 상태는 "호버되지 않음"입니다.
onLeave()Draggable
NextSelectionDown
코드 샘플
게임패드 선택 그리드 만들기
-- 아래 코드를 사용하여 게임패드 선택 그리드를 설정합니다
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
-- 왼쪽 끝
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- 오른쪽 끝
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- 위
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- 아래
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- 아래 코드를 사용하여 게임패드 선택 그리드를 테스트합니다
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
코드 샘플
게임패드 선택 그리드 만들기
-- 아래 코드를 사용하여 게임패드 선택 그리드를 설정합니다
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
-- 왼쪽 끝
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- 오른쪽 끝
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- 위
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- 아래
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- 아래 코드를 사용하여 게임패드 선택 그리드를 테스트합니다
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
코드 샘플
게임패드 선택 그리드 만들기
-- 아래 코드를 사용하여 게임패드 선택 그리드를 설정합니다
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
-- 왼쪽 끝
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- 오른쪽 끝
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- 위
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- 아래
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- 아래 코드를 사용하여 게임패드 선택 그리드를 테스트합니다
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
코드 샘플
게임패드 선택 그리드 만들기
-- 아래 코드를 사용하여 게임패드 선택 그리드를 설정합니다
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
-- 왼쪽 끝
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- 오른쪽 끝
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- 위
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- 아래
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- 아래 코드를 사용하여 게임패드 선택 그리드를 테스트합니다
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
코드 샘플
텍스트 박스 선택 제한
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
-- FocusLost 및 FocusGained 이벤트가 fire될 것입니다, 왜냐하면 textBox
--는 TextBox 유형입니다
textBox.Focused:Connect(gainFocus)
textBox.FocusLost:Connect(loseFocus)Size
코드 샘플
체력 바
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- 스크립트를 프레임 내의 프레임에
-- 부모가 된 LocalScript에 붙여넣으세요
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- 검정색
-- 이 함수는 인간의 체력이 변경될 때 호출됩니다
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- 내부 바의 크기를 변경합니다
frame.Size = UDim2.new(percent, 0, 1, 0)
-- 체력 바의 색상을 변경합니다
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- 검정색
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- 노란색
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- 초록색
end
end
-- 이 함수는 플레이어가 스폰될 때 호출됩니다
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- 패턴: 지금 한 번 업데이트한 후 체력이 변경될 때마다
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- 우리의 스폰 리스너를 연결합니다; 이미 스폰된 경우 호출합니다
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
endTransparency
Visible
코드 샘플
UI 창
local gui = script.Parent
local window = gui:WaitForChild("Window")
local toggleButton = gui:WaitForChild("ToggleWindow")
local closeButton = window:WaitForChild("Close")
local function toggleWindowVisbility()
-- 불린 값을 `not` 키워드를 사용하여 뒤집기
window.Visible = not window.Visible
end
toggleButton.Activated:Connect(toggleWindowVisbility)
closeButton.Activated:Connect(toggleWindowVisbility)메서드
TweenPosition
TweenSize
TweenSizeAndPosition
이벤트
DragBegin
DragStopped
InputBegan
매개 변수
코드 샘플
GuiObject에서 입력 시작 추적
-- InputBegan 이벤트를 사용하려면 GuiObject를 지정해야 합니다.
local gui = script.Parent
-- 다양한 유형의 사용자 입력에 대한 여러 사용 사례를 제공하는 샘플 함수입니다.
local function inputBegan(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("키가 눌렸습니다! 키:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("왼쪽 마우스 버튼이", input.Position, "에서 눌렸습니다.")
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("오른쪽 마우스 버튼이", input.Position, "에서 눌렸습니다.")
elseif input.UserInputType == Enum.UserInputType.Touch then
print("터치스크린 입력이", input.Position, "에서 시작되었습니다.")
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("게임패드에서 버튼이 눌렸습니다! 버튼:", input.KeyCode)
end
end
gui.InputBegan:Connect(inputBegan)InputChanged
매개 변수
코드 샘플
GuiObject 입력 변경 데모
local UserInputService = game:GetService("UserInputService")
local gui = script.Parent
local function printMovement(input)
print("위치:", input.Position)
print("이동 델타:", input.Delta)
end
local function inputChanged(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
print("마우스가 이동했습니다!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
print("마우스 휠이 스크롤되었습니다!")
print("휠 이동:", input.Position.Z)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.Thumbstick1 then
print("왼쪽 스틱이 이동했습니다!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
print("오른쪽 스틱이 이동했습니다!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
print("왼쪽 트리거에 가해진 압력이 변경되었습니다!")
print("압력:", input.Position.Z)
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
print("오른쪽 트리거에 가해진 압력이 변경되었습니다!")
print("압력:", input.Position.Z)
end
elseif input.UserInputType == Enum.UserInputType.Touch then
print("사용자의 손가락이 화면에서 이동하고 있습니다!")
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("사용자의 모바일 장치의 회전이 변경되었습니다!")
print("위치", rotCFrame.p)
print("회전:", rot)
elseif input.UserInputType == Enum.UserInputType.Accelerometer then
print("사용자의 모바일 장치의 가속도가 변경되었습니다!")
printMovement(input)
end
end
gui.InputChanged:Connect(inputChanged)InputEnded
매개 변수
코드 샘플
GuiObject의 입력 종료 추적
-- InputChanged 이벤트를 사용하려면 GuiObject를 지정해야 합니다.
local gui = script.Parent
-- 다양한 유형의 사용자 입력을 위한 여러 사용 사례를 제공하는 샘플 함수
local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("키가 해제되었습니다! 키:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("왼쪽 마우스 버튼이 해제되었습니다:", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("오른쪽 마우스 버튼이 해제되었습니다:", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("터치스크린 입력이 해제되었습니다:", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("게임패드에서 버튼이 해제되었습니다! 버튼:", input.KeyCode)
end
end
gui.InputEnded:Connect(inputEnded)MouseEnter
코드 샘플
GuiObject에 마우스가 들어갈 때 출력하기
local guiObject = script.Parent
guiObject.MouseEnter:Connect(function(x, y)
print("사용자의 마우스 커서가 GuiObject 위치에 들어왔습니다", x, ",", y)
end)MouseWheelBackward
MouseWheelForward
SelectionGained
코드 샘플
GUI 선택 처리
local guiObject = script.Parent
local function selectionGained()
print("사용자가 게임패드를 사용하여 이 버튼을 선택했습니다.")
end
guiObject.SelectionGained:Connect(selectionGained)SelectionLost
코드 샘플
GUI 선택 잃어버림 처리
local guiObject = script.Parent
local function selectionLost()
print("사용자가 더 이상 게임패드로 선택하지 않았습니다.")
end
guiObject.SelectionLost:Connect(selectionLost)TouchLongPress
매개 변수
코드 샘플
터치 롱프레스를 이용한 UI 요소 이동
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
-- 드래그 시작
dragging = true
basePosition = frame.Position
startTouchPosition = touchPositions[1]
-- 드래그가 진행 중임을 나타내기 위해 프레임 색상 변경
borderColor3 = frame.BorderColor3
backgroundColor3 = frame.BackgroundColor3
frame.BorderColor3 = Color3.new(1, 1, 1) -- 흰색
frame.BackgroundColor3 = Color3.new(0, 0, 1) -- 파란색
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
-- 드래그 중지
dragging = false
frame.BorderColor3 = borderColor3
frame.BackgroundColor3 = backgroundColor3
end
end
frame.TouchLongPress:Connect(onTouchLongPress)TouchPan
GuiObject.TouchPan(
매개 변수
코드 샘플
팬닝 UI 요소
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(
매개 변수
코드 샘플
집게/끌어당기기 크기 조절
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 -- 여기에서 곱셈을 주목하세요
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPinch:Connect(onTouchPinch)TouchRotate
GuiObject.TouchRotate(
매개 변수
코드 샘플
터치 회전
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
매개 변수
코드 샘플
튀는 색상 선택기
local frame = script.Parent
frame.Active = true
-- 성공적인 스와이프에서 프레임이 튕길 거리
local BOUNCE_DISTANCE = 50
-- 프레임의 현재 상태
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)
-- 스와이프 방향에 따라 BackgroundColor3를 변경합니다.
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
-- 색상을 업데이트하고 프레임을 약간 튕깁니다.
updateColor()
frame.Position = basePosition + deltaPos
frame:TweenPosition(basePosition, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 0.7, true)
end
frame.TouchSwipe:Connect(onTouchSwipe)
updateColor()TouchTap
매개 변수
코드 샘플
투명도 전환 버튼
local frame = script.Parent
frame.Active = true
local function onTouchTap()
-- 배경 투명도 전환
if frame.BackgroundTransparency > 0 then
frame.BackgroundTransparency = 0
else
frame.BackgroundTransparency = 0.75
end
end
frame.TouchTap:Connect(onTouchTap)