Keyframe

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

钥匙帧保留在动画中应用于节点的 在指定时间点的时间,在一个动画中。Keyframes 在动画播放期间被插入。

请注意,在大多数情况下,开发人员不需要操作 KeyframeSequences ,因为动画编辑器覆盖了大部分动画功能。然而,在某些情况下,开发者可能希望从 Script 或构建自己的插件生成动画。

结构

关键帧被保持在 KeyframeSequence 内,包含 Pose 个对象。姿势的名称与它们对应的 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 时间将被显示的时间。

注意在 中使用最高时间值来确定动画的长度。

代码示例

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 为姿势参数时,此函数不会出错,并且会成功地将其作为父级。

参数

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 的阵列。注意,此函数只会返回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.Parent 中移除一个 nil

键帧标记器的 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

活动