Class.Path2D 實個體、實例,包括其 API 方法和屬性,讓您實現 2D 曲線和 2D 彎曲線,有助於路徑基礎動畫和圖形編輯器的 UI 效果。
建立 2D 道路徑
要將 Path2D 添加到屏幕或體驗中的對物件:
在 Explorer 窗口中,在可見的 Class.ScreenGui 或 Class.SurfaceGui 下插入一個 1>Class.Path2D1> 實例。
選擇新的 Path2D 以顯示視窗工具小工具。 預設值下,選擇 添加點 工具。
完成後,按下 widget 的 完成 按鈕或按下 按入 。
修改控制點
在 Path2D 階層中選擇了 Class.Path2D ,你可以修改其個別控制點以及其 tangents。
移動點
要在路徑上移動控制點,啟用 選取 工具 ( V ) 然後按一下並拖曳它到新位置。


對於非常具體的位置,選擇控制點,然後,在 屬性 窗口中,為點的 SelectedControlPointData 屬性設置新位置 ( UDim2 )。

注意點的位置不是絕對,而是相對於路徑的父容器。例如,比較控制點 30% 從左邊和 20% 從頂部為路徑內的一個路徑,而不是放置在 ScreenGui 內的相同路徑。當放置在 Class.Frame

增加點數
新控制點可以在兩個現有點之間或從使用 Path2D 工具 ( P ) 的任意一端點上添加新控制點。



刪除點
要刪除控制點,請將鼠標指针移動至控制點右邊,然後從上下文提示菜單中選擇 刪除點 。

控制點軌道
控制點 棱角 讓您可以在路徑上創建並調整曲線。

增加方向
要將軌道添加到任何尚未有軌道的控制點:
啟用 Add Tangent 工具在工具小工具中。
將鼠標擺置在所需控制點上,然後按一下以添加兩個 鏡像 切角 (可選) 。
調整方向角
要調整個別控制點的現有棱角:
啟用 選取工具 ( V 工具 ) 。
將鼠標揮動在控制點上,然後點擊並拖曳它到新位置。如果控制點是鏡像,則會移動雙方的控制點。
要手動設置特定 UDim2 位置以對齒輪:
啟用 選取 工具 ( V ) 並選擇控制點。在 屬性 窗口中,擴展 1> Class.Path2D.SelectedControlPointData|SelectedControlPointData1> 字段來顯示 4> Datatype.Path
設置位置為 LeftTangent 和/或 RightTangent 。注意這會導致鏡像行為的變更。
刪除接線
要從控制點移除兩個軸從,將鼠標移動至該點,然後右鍵點擊,然後從上下文菜單中選擇 清除軸 。

要刪除只有一個角度 (左或右) ,將鼠標放在該角度的標記上,然後選擇 刪除角度 。

斷條和鏡像
由預設,讓齒輪鏡齒相互。當您拖曳以調整一個齒輪標記時,雙方的齒輪點將在協調中移動。

要將軸對稱分開,讓每個人都可以獨立於另一個人,將鼠標指针移動到與軸對稱的位置,然後從上下文菜單中選擇 軸對稱 。破損後,您可以移動每個軸標記,不會影響其他人。

道路視覺特性
您可以使用以下屬性自訂 Path2D 的視覺外觀:



路徑指令碼
腳本對於多個路徑相關工作流程有用。以下例子使用了方法 such as GetControlPoints() ,這會返回一個表 of Datatype.Path2DControlPoint|Path2D
在路徑上排列 UI 對象
local parent = script.Parent
local path = parent:FindFirstChildWhichIsA("Path2D")
local function arrangeChildren()
local segmentCount = #path:GetControlPoints()
local objectsToArrange = {}
for _, child in parent:GetChildren() do
if child:IsA("GuiObject") then
table.insert(objectsToArrange, child)
end
end
for idx, child in objectsToArrange do
local t = idx / (#objectsToArrange + 1)
child.Position = path:GetPositionOnCurveArcLength(t)
end
end
-- 初始設置子兒童 UI 對象在路徑上
arrangeChildren()
-- 聆聽孩子被添加/移除以調整配置
parent.ChildAdded:Connect(arrangeChildren)
parent.ChildRemoved:Connect(arrangeChildren)
以路徑上的動畫介面對象
local Tweenservice = game:GetService("TweenService")
local parent = script.Parent
local path = parent:FindFirstChildWhichIsA("Path2D")
local objectToAnimate = parent:FindFirstChildWhichIsA("GuiObject")
local TWEEN_DURATION = 4
local TWEEN_EASING_STYLE = Enum.EasingStyle.Cubic
local TWEEN_EASING_DIRECTION = Enum.EasingDirection.InOut
local pathSampleValue = Instance.new("NumberValue")
local tweenInfo = TweenInfo.new(TWEEN_DURATION, TWEEN_EASING_STYLE, TWEEN_EASING_DIRECTION, 0, true, 2)
local tween = Tweenservice:Create(pathSampleValue, tweenInfo, {Value = 1})
local function onSampleValueChanged()
objectToAnimate.Position = path:GetPositionOnCurveArcLength(pathSampleValue.Value)
end
pathSampleValue.Changed:Connect(onSampleValueChanged)
tween:Play()