Greetings Everyone.
-
What do you want to achieve? :
I’m trying to draw a line between two UI (using a Frame). So far the line script work as I can see.
This two UI here are the point A and B for drawing the line.
But his position and his scale are not relative to the parent UI, so the line didn’t appear because it is far away from it’s target.
-
What solutions have you tried so far?:
I try to use a offset to scale code. This code work perfectly on UI directly parented to a GUI object.
function OffsetToScale(Offset,targetUI)
local viewPortSize = workspace.CurrentCamera.ViewportSize
return UDim2.new(Offset[1] / viewPortSize.X, 0, Offset[2] / viewPortSize.Y, 0)
end
So it didn’t work so well on that line because the line his parented to a frame.
And here his the code for drawing a line between two UI.
local VECTOR2_HALF = Vector2.new(0.5, 0.5)
function DrawLineFromTwoPoints(lineFrame:Frame , pointA , pointB)
lineFrame.Size = UDim2.fromOffset(
math.sqrt((pointA.X - pointB.X) ^ 2 + (pointA.Y - pointB.Y) ^ 2), 2)
lineFrame.Position = UDim2.fromOffset(
(pointA.X + pointB.X) / 2,
(pointA.Y + pointB.Y) / 2
)
lineFrame.Rotation = math.deg(math.atan2((pointA.Y - pointB.Y), (pointA.X - pointB.X)))
lineFrame.AnchorPoint = VECTOR2_HALF
return lineFrame
end
function DrawLineUI(lineFrame:Frame, obj1, obj2)
-- Get center regardless of anchor point
local posA = obj1.AbsolutePosition + (obj1.AbsoluteSize * VECTOR2_HALF)
local posB = obj2.AbsolutePosition + (obj2.AbsoluteSize * VECTOR2_HALF)
return DrawLineFromTwoPoints(lineFrame, posA, posB)
end
And here the code I use to call all of the function.
local lineNew = DrawLineUI(lineSkillTree:Clone(),skillFrame,frameLinkedTo.Value)
lineNew.Position = OffsetToScale({lineNew.Position.X.Offset,lineNew.Position.Y.Offset},moverFrame)
lineNew.Size = OffsetToScale({lineNew.Size.X.Offset,lineNew.Size.Y.Offset},moverFrame)
lineNew.Parent = moverFrame.LineStorage
And the actual workspace configuration :
Thanks just after read this mess. And thanks if you help me.