Class.Pose|Poses 在瞬間移動到另一個點的時間表中,在動畫中與關節結合在一起。Model 在動畫播放時間間隔中交錯。
注意,在大多數情況下,開發人員不需要操作 KeyframeSequences ,因為動畫編輯器涵蓋大多數動畫功能。但在一些情況下,開發人員可能希望從 Script 或建立自己的外掛程式中生成動畫。
結構
鑰匙框是由 KeyframeSequence 內的一個子集,包含 Pose 對象。鑰匙框的名稱是根據它們與相應的 BaseParts 對應而且結構在共同階層
注意,Poses 以 BaseParts 的名稱來命名,動畫需要正確播放。
插件
在播放動畫時,在不同的鍵盤中,位置在不同的畫面之間是相互交錯的。這允許創建一個平滑的動畫,而不需要定義每個畫面。注意,鍵盤對象只是在動畫中的特定時間點 ( Class.Pose|Poses) 中保持。 時間 對象只是
範例程式碼
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.
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)
概要
方法
將 KeyframeMarker 添加到 Keyframe 由於它的父親,它將能夠綁定到關鍵格。
返回包含 KeyframeMarkers 全部已添加到 Keyframe 的列表。
從 KeyframeMarker 移除它從 Keyframe 的設定,將其 Instance.Parent 設為零。
將 Pose 從 Keyframe 設置為零,將其 Instance.Parent 設置為零。
屬性
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.
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 的父級,它與設置標記的 2>Class.Instance.Parent2> 相同。
注意,此功能不會在 Keyframe Marker 以外的實例作為參數而發生錯誤,並且會成功擁有它。
更多關於鑰匙框
Keyframe 名稱不需要是唯一的。例如,如果有三個名為 "Particles" 的關鍵框,連接的事件由 AnimationTrack:GetMarkerReachedSignal() 返回時,每次一個關鍵框達到時,發射將會發生。
Keyframe 但 Script 在播放動畫之前無法設置它們。
也看:
參數
返回
範例程式碼
This example demonstrates the Keyframe:AddMarker() and Keyframe:RemoveMarker() functions. Note these are functionally equivalent to parenting and un-parenting the markers.
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 以外的實例為姿勢參數時,此功能不會發生錯誤,且將成功擁有它。
參數
返回
範例程式碼
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.
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.
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
此功能返回包含所有 KeyframeMarkers 已添加到 Keyframe 的所有列表。注意,此功能只會返回 instances 的 1>KeyframeMarker1> 類型。
更多關於鑰匙框
Keyframe 名稱不需要是唯一的。例如,如果有三個名為 "Particles" 的關鍵框,連接的事件由 AnimationTrack:GetMarkerReachedSignal() 返回時,每次一個關鍵框達到時,發射將會發生。
Keyframe 但 Script 在播放動畫之前無法設置它們。
也看:
返回
一個包含所有 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.
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
此函數返回包含所有 Poses 的陣列,其中已添加到 Keyframe 。
返回
一個 Poses 的陣列。
範例程式碼
This code sample includes a function to reset the CFrame of the Poses in a Keyframe.
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
此功能將 KeyframeMarker 從 Keyframe 中移除設定,將其 Instance.Parent 設為零。
鑰匙框標記的 Instance.Parent 設為空,但不會被摧毀。這表示,只要標記稍後引用,它就可以重新指定。
注意,此功能不會在 Keyframe Marker 以外的實例作為參數時發生錯誤。
更多關於鑰匙框
Keyframe 名稱不需要是唯一的。例如,如果有三個名為 "Particles" 的關鍵框,連接的事件由 AnimationTrack:GetMarkerReachedSignal() 返回時,每次一個關鍵框達到時,發射將會發生。
Keyframe 但 Script 在播放動畫之前無法設置它們。
也看:
參數
返回
範例程式碼
This example demonstrates the Keyframe:AddMarker() and Keyframe:RemoveMarker() functions. Note these are functionally equivalent to parenting and un-parenting the markers.
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
此功能從 Pose 從 Keyframe 設定它的 Instance.Parent 為 1> nil1> 而不需要摧毀它。這意味著提供的姿勢是引用的,它可以稍後重新親和。
注意,此功能在 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.
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