Keyframe

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

鑰匙框在特定時間點的動畫中保留 Poses 應用於動畫中的節點上的 ModelKeyframes 在動畫播放期間會被插入。

請注意,在大多數情況下,開發人員不需要操作 KeyframeSequences ,因為動畫編輯器覆蓋了大多數動畫功能。然而,在某些情況下,開發者可能希望從 Script 或構建自己的外掛程式來生成動畫。

結構

鑰匙框在 KeyframeSequence 內保持,包含 Pose 個對象。姿勢的名稱會依照它們對應的 BaseParts 進行命名,並以共同層級的方式結構化。這意味著每個 Pose 都被指派到與它附帶的部分相對應的 Pose

注意, 如果 Poses 以符合 BaseParts 命名, 動畫需要不同的部分名稱才能正確播放。

插值

在動畫播放期間,不同鑰匙框的姿勢會在之間互相融合。這樣可以創建一個平滑的動畫,而不需要定義每一個框架。注意,插值風格在 Pose 對物件中被決定。鑰匙框對象只持有 Poses 在動畫中定義的時刻點 ( Keyframe.Time )。

範例程式碼

This sample includes a function that will generate a 'blank' keyframe containing blank poses for all of the model's connected parts in the correct hierarchical order.

Keyframe Generate Poses

local function generateKeyframe(model)
if not model.PrimaryPart then
warn("No primary part set")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Root part not found")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part, parentPose)
-- get all of the joints attached to the part
for _, joint in pairs(part:GetJoints()) do
-- we're only interested in Motor6Ds
if joint:IsA("Motor6D") then
-- find the connected part
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- make sure we haven't already added this part
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
-- create a pose
local pose = Instance.new("Pose")
pose.Name = connectedPart.Name
parentPose:AddSubPose(pose)
-- recurse
addPoses(connectedPart, pose)
end
end
end
end
end
local keyframe = Instance.new("Keyframe")
-- populate the keyframe
local rootPose = Instance.new("Pose")
rootPose.Name = rootPart.Name
addPoses(rootPart, rootPose)
keyframe:AddPose(rootPose)
return keyframe
end
local character = script.Parent
local keyframe = generateKeyframe(character)
print(keyframe)

概要

屬性

  • 平行讀取

    在動畫中的 Keyframe 時間位置 (以秒為單位)。這會決定在鑰匙框內顯示的 Poses 時間。

方法

屬性

Time

平行讀取

此屬性在動畫中提供 Keyframe 時間位置 (以秒為單位) 。這會決定鑰匙框內的 Poses 時間何時會顯示。

注意 Keyframe 中使用最高時間值來確定動畫長度的 KeyframeSequence

範例程式碼

This sample contains a simple function that will get the length of a KeyframeSequence by finding the Keyframe with the highest Keyframe.Time value.

Get KeyframeSequence Length

local function getSequenceLength(keyframeSequence)
local length = 0
for _, keyframe in pairs(keyframeSequence:GetKeyframes()) do
if keyframe.Time > length then
length = keyframe.Time
end
end
return length
end
local keyframeSequence = Instance.new("KeyframeSequence")
getSequenceLength(keyframeSequence)

方法

AddMarker

()

這個功能會將 KeyframeMarker 添加到 Keyframe 的父輩骨架上,以便將它添加到關鍵格。它的功能與設置標記的 Instance.Parent 到鑰匙框相同。

注意,當 KeyframeMarker 以外的實例作為參數提供時,此功能不會發生錯誤,並且會成功地將其作為父級。

關於鑰匙框的更多信息

Keyframe 名稱不需要獨一無二。例如,如果動畫有三個名為「粒子」的關鍵幀,連接到的事件由 AnimationTrack:GetMarkerReachedSignal() 每次達到這些關鍵幀之一時發射。

Keyframe 名稱可以在 Roblox 動畫編輯器中設置,當創建或編輯動畫時。然而,它們無法在播放之前在現有動畫上設置 Script

也見:

參數

marker: Instance

正在將 KeyframeMarker 指派給 Keyframe

預設值:""

返回

()

範例程式碼

This example demonstrates the Keyframe:AddMarker() and Keyframe:RemoveMarker() functions. Note these are functionally equivalent to parenting and un-parenting the markers.

Add Marker/Remove Marker

local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker = Instance.new("KeyframeMarker")
marker.Name = "FootStep"
marker.Value = 100
keyframe:AddMarker(marker) --marker.Parent = keyframe
task.wait(2)
keyframe:RemoveMarker(marker) --marker.Parent = nil

AddPose

()

這個功能會將 Pose 添加到 Keyframe 的父輩骨架上,以便將它添加到關鍵格。它的功能與設置姿勢的 Instance.Parent 到關鍵格相同。

注意,當給予模型參數以外的實例作為姿勢參數時,此功能不會發生錯誤,並且會成功地將其作為父級。

參數

pose: Instance

要添加的 Pose

預設值:""

返回

()

範例程式碼

This sample includes a function that will generate a 'blank' keyframe containing blank poses for all of the model's connected parts in the correct hierarchical order.

Keyframe Generate Poses

local function generateKeyframe(model)
if not model.PrimaryPart then
warn("No primary part set")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Root part not found")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part, parentPose)
-- get all of the joints attached to the part
for _, joint in pairs(part:GetJoints()) do
-- we're only interested in Motor6Ds
if joint:IsA("Motor6D") then
-- find the connected part
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- make sure we haven't already added this part
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
-- create a pose
local pose = Instance.new("Pose")
pose.Name = connectedPart.Name
parentPose:AddSubPose(pose)
-- recurse
addPoses(connectedPart, pose)
end
end
end
end
end
local keyframe = Instance.new("Keyframe")
-- populate the keyframe
local rootPose = Instance.new("Pose")
rootPose.Name = rootPart.Name
addPoses(rootPart, rootPose)
keyframe:AddPose(rootPose)
return keyframe
end
local character = script.Parent
local keyframe = generateKeyframe(character)
print(keyframe)

This sample demonstrates quickly the Keyframe.AddPose, Keyframe.RemovePose and Pose.AddSubPose and Pose.RemoveSubPose functions. Note these are functionally equivalent to parenting and un-parenting the poses.

Keyframe Add/Remove Pose

local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
keyframe:RemovePose(pose) -- pose.Parent = nil
task.wait(2)
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
pose:AddSubPose(pose2) -- pose2.Parent = pose
task.wait(2)
pose:RemoveSubPose(pose2) -- pose2.Parent = nil

GetMarkers

Instances

此功能返回包含所有 KeyframeMarkers 已添加到 Keyframe 的 array。注意,此功能只會返回instances類型KeyframeMarker的值。

關於鑰匙框的更多信息

Keyframe 名稱不需要獨一無二。例如,如果動畫有三個名為「粒子」的關鍵幀,連接到的事件由 AnimationTrack:GetMarkerReachedSignal() 每次達到這些關鍵幀之一時發射。

Keyframe 名稱可以在 Roblox 動畫編輯器中設置,當創建或編輯動畫時。然而,它們無法在播放之前在現有動畫上設置 Script

也見:


返回

Instances

包含所有 KeyframeMarkers 已添加到 Keyframe 的數組。

範例程式碼

This example demonstrates the Keyframe:AddMarker() and Keyframe:GetMarkers() functions. After adding two markers, marker1 and marker2 to the keyframe, this example gets and prints the names of the added markers.

Get Keyframe Markers Attached to a Keyframe

local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker1 = Instance.new("KeyframeMarker")
marker1.Name = "FootStep"
marker1.Value = 100
local marker2 = Instance.new("KeyframeMarker")
marker2.Name = "Wave"
marker2.Value = 100
keyframe:AddMarker(marker1) --marker.Parent = keyframe
keyframe:AddMarker(marker2) --marker.Parent = keyframe
local markers = keyframe:GetMarkers()
for _, marker in pairs(markers) do
print(marker.Name)
end

GetPoses

Instances

此功能返回包含所有 Poses 已添加到 Keyframe 的數組。


返回

Instances

一個 Poses 陣列。

範例程式碼

This code sample includes a function to reset the CFrame of the Poses in a Keyframe.

Keyframe Reset Poses

local function resetPoses(parent)
-- both functions are equivalent to GetChildren
local poses = parent:IsA("Keyframe") and parent:GetPoses() or parent:IsA("Pose") and parent:GetSubPoses()
for _, pose in pairs(poses) do
if pose:IsA("Pose") then
pose.CFrame = CFrame.new()
-- recurse
resetPoses(pose)
end
end
end

RemoveMarker

()

此功能會將 KeyframeMarkerKeyframe 移除,設置其 Instance.Parentnil

鑰匙框標記器的 Instance.Parent 設為 nil 但未被摧毀。這意味著,只要標記被引用,它之後就可以被重新領養。

注意,當 KeyframeMarker 以外的實例作為參數提供時,此功能不會發生錯誤。

關於鑰匙框的更多信息

Keyframe 名稱不需要獨一無二。例如,如果動畫有三個名為「粒子」的關鍵幀,連接到的事件由 AnimationTrack:GetMarkerReachedSignal() 每次達到這些關鍵幀之一時發射。

Keyframe 名稱可以在 Roblox 動畫編輯器中設置,當創建或編輯動畫時。然而,它們無法在播放之前在現有動畫上設置 Script

也見:

參數

marker: Instance

標記正在從 Keyframe 移除。

預設值:""

返回

()

範例程式碼

This example demonstrates the Keyframe:AddMarker() and Keyframe:RemoveMarker() functions. Note these are functionally equivalent to parenting and un-parenting the markers.

Add Marker/Remove Marker

local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker = Instance.new("KeyframeMarker")
marker.Name = "FootStep"
marker.Value = 100
keyframe:AddMarker(marker) --marker.Parent = keyframe
task.wait(2)
keyframe:RemoveMarker(marker) --marker.Parent = nil

RemovePose

()

此功能會將 PoseKeyframe 移除,設置其 Instance.Parentnil 而不會毀滅它。這意味著提供的姿勢已被參考,並可以稍後重新父系化。

注意,當指示參數為除 Pose 以外的實例時,此功能不會發生錯誤。

參數

pose: Instance

要移除的 Pose

預設值:""

返回

()

範例程式碼

This sample demonstrates quickly the Keyframe.AddPose, Keyframe.RemovePose and Pose.AddSubPose and Pose.RemoveSubPose functions. Note these are functionally equivalent to parenting and un-parenting the poses.

Keyframe Add/Remove Pose

local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
keyframe:RemovePose(pose) -- pose.Parent = nil
task.wait(2)
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
pose:AddSubPose(pose2) -- pose2.Parent = pose
task.wait(2)
pose:RemoveSubPose(pose2) -- pose2.Parent = nil

活動