-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragAndDropModule.luau
More file actions
87 lines (73 loc) · 2.55 KB
/
DragAndDropModule.luau
File metadata and controls
87 lines (73 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-- Getting Services
local Players = game:GetService("Players")
-- Starting Objects
dragAndDropModule = {}
local objectToMove
local move = false
local passedPixelDelay = false
local clickInsideFrameX
local clickInsideFrameY
local firstClickPosX
local firstClickPosY
local lastPosition
local lastSize
local endStart = true
-- settings
dragAndDropModule.usePixelDelayToMove = false
dragAndDropModule.pixelDelayToMove = 20
dragAndDropModule.backToPosAfterDrag = false
-- Main
function dragAndDropModule.setObjectToMove(passedObject)
objectToMove = passedObject
end
function dragAndDropModule.frameInteractStart(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
move = true
local mousePos = game.Players.LocalPlayer:GetMouse()
clickInsideFrameX = mousePos.X - objectToMove.AbsolutePosition.X
clickInsideFrameY= mousePos.Y - objectToMove.AbsolutePosition.Y
firstClickPosX = mousePos.X
firstClickPosY = mousePos.Y
lastSize = objectToMove.Size
lastPosition = objectToMove.Position
objectToMove.Size = UDim2.new(0,objectToMove.AbsoluteSize.X,0,objectToMove.AbsoluteSize.Y)
local absolutePostion = objectToMove.AbsolutePosition
objectToMove.Position = UDim2.new(0,absolutePostion.X,0,absolutePostion.Y)
end
end
function dragAndDropModule.frameInteractEnd(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if not endStart then
return
end
endStart = false
move = false
passedPixelDelay = false
local mousePos = game.Players.LocalPlayer:GetMouse()
local backToPlace = true
if dragAndDropModule.backToPosAfterDrag then
if backToPlace then
objectToMove.Position = lastPosition
objectToMove.Size = lastSize
end
end
task.wait(0.3)
endStart = true
end
end
function dragAndDropModule.updateMove()
local mousePos = game.Players.LocalPlayer:GetMouse()
if move then
if dragAndDropModule.usePixelDelayToMove then
if mousePos.X-firstClickPosX > dragAndDropModule.pixelDelayToMove or mousePos.X-firstClickPosX < -dragAndDropModule.pixelDelayToMove or
mousePos.Y-firstClickPosY > dragAndDropModule.pixelDelayToMove or mousePos.Y-firstClickPosY < -dragAndDropModule.pixelDelayToMove then passedPixelDelay = true
end
if passedPixelDelay then
objectToMove.Position = UDim2.new(0,mousePos.X-clickInsideFrameX,0,mousePos.Y-clickInsideFrameY)
end
else
objectToMove.Position = UDim2.new(0,mousePos.X-clickInsideFrameX,0,mousePos.Y-clickInsideFrameY)
end
end
end
return dragAndDropModule