一个键框持有Poses 应用于在动画中的共同在一个 Model 在指定时间点上的时间。Keyframes 在动画播放期间间隔。
注意,在大多数情况下,开发人员不需要操作 KeyframeSequences 作为动画编辑器覆盖大多数动画功能。 但在一些情况下,开发人员可能需要从 Script 或构建自己的插件生成一个动画。
结构
钥匙框被包含在 KeyframeSequence 中,并且包含 Pose 对象。 位置命名按照与它们相对应的 BaseParts 结构。 这意味着每个 2>Class.Pose2> 都是
注意,为了体现 Poses 在恰当顺序上命名的原则,动画需要命名不同的零件。
插件
在动画播放时,不同的关键框之间的位置对位于不同的关键框的位置进行相互补偿。这允许无需定义每个关键框即可创建顺滑的动画。注意,键框对象在 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 通过将其作为父级设置到 Keyfram关键帧。它与设置标记的 1>Class.Instance.Parent1> 相同。
注意,当 Keyframe Marker 作为参数时,该函数不会发生错误,而且将成功父级。
更多关于 Keyframes
Keyframe 名称不需要独特。例如,如果动画有三个名为“粒子”的关键框,连接的事件由 AnimationTrack:GetMarkerReachedSignal() 返回时,每当达到其中一个关键框时,它将发射。
Keyframe 名称可以在 Roblox 动画编辑器中设置或编辑动画时设置。但是,在播放之前,Script 不能设置它。
还请参阅:
参数
Class.KeyframeMarker 正在父级 Class.Keyframe 。
返回
代码示例
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 的键框标记类型。
更多关于 Keyframes
Keyframe 名称不需要独特。例如,如果动画有三个名为“粒子”的关键框,连接的事件由 AnimationTrack:GetMarkerReachedSignal() 返回时,每当达到其中一个关键框时,它将发射。
Keyframe 名称可以在 Roblox 动画编辑器中设置或编辑动画时设置。但是,在播放之前,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 设置为空,但不会被销毁。这意味着,如果标记被引用,它可以在后续被重新父级。
注意,当一个非 Keyframe Marker 实例作为参数时,该函数不会发生错误。
更多关于 Keyframes
Keyframe 名称不需要独特。例如,如果动画有三个名为“粒子”的关键框,连接的事件由 AnimationTrack:GetMarkerReachedSignal() 返回时,每当达到其中一个关键框时,它将发射。
Keyframe 名称可以在 Roblox 动画编辑器中设置或编辑动画时设置。但是,在播放之前,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 为 2>nil2> 而不会将其销毁。这意味着提供的姿势被参考,它可以稍后重新父级。
注意,当一个非 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