Keyframe

Visualizza obsoleti

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.

Un Keyframe contiene il Poses applicato alle articolazioni in un Model a un punto di tempo dato in un'animazioni.Keyframes sono interpolati tra durante il riproduzione dell'animazione.

Nota, nella maggior parte dei casi gli sviluppatori non hanno bisogno di manipolare KeyframeSequences come l'editor di animazione copre la maggior parte della funzionalità di animazione.Tuttavia, in alcuni casi un sviluppatore potrebbe voler generare un'animazione da un Script o costruire il proprio Collegare.

Struttura

I keyframe sono contenuti all'interno di un KeyframeSequence e contengono oggetti Pose .Le pose sono nominate in conformità con la BaseParts a cui corrispondono e sono strutturate in termini di gerarchia congiunta.Questo significa che ogni Pose è genitoriale al Pose corrispondente alla parte a cui è allegato.

Nota, come Poses sono nominati in conformità con il BaseParts a cui corrispondono, le animazioni richiedono nomi di parti distinti per giocare correttamente.

Interpolazione

Durante la riproduzione dell'animazione le pose in diversi keyframe vengono interpolate tra loro.Questo consente di creare un'animazione liscia senza dover definire ogni frame.Nota, lo stile di interpolazione è determinato nell'oggetto Pose.L'oggetto Keyframe contiene semplicemente il Poses a un punto di tempo definito nell'animazione (Keyframe.Time).

Campioni di codice

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)

Sommario

Proprietà

  • Lettura Parallela

    La posizione temporale Keyframe (in secondi) in un'animazioni. Questo determina l'ora in cui verrà mostrato l'interno del keyframe Poses.

Metodi

Proprietà

Time

Lettura Parallela

Questa proprietà dà la posizione temporale Keyframe in un'animazioni(in secondi).Questo determina il momento in cui verrà mostrato il Poses all'interno del keyframe.

Nota il Keyframe con il valore temporale più elevato in un KeyframeSequence viene utilizzato per determinare la lunghezza dell'animazioni.

Campioni di codice

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)

Metodi

AddMarker

()

Questa funzione aggiunge un KeyframeMarker alla Keyframe da genitore al Fotogramma chiave.È funzionalmente identico a impostare il segnaposto Instance.Parent al Keyframe.

Nota, questa funzione non darà errore quando un'istanza diversa da un KeyframeMarker viene data come parametro e la genitorerà con successo.

Altro su Keyframes

Keyframe i nomi non devono essere unici.Ad esempio, se un'Animazione ha tre keyframe chiamati "Particelle" l'evento connesso restituito da AnimationTrack:GetMarkerReachedSignal() sarà attivato ogni volta che viene raggiunto uno di questi keyframe.

Keyframe i nomi possono essere impostati nell'Editor di animazione Roblox quando si crea o modifica un'animazioni.Non possono tuttavia essere impostati da un Script su un'animazione esistente prima di giocarci.

Vedi anche:

Parametri

marker: Instance

Il KeyframeMarker viene genitorato al Keyframe .

Valore predefinito: ""

Restituzioni

()

Campioni di codice

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

()

Questa funzione aggiunge un Pose alla Keyframe da genitore al Fotogramma chiave.È funzionalmente identico a impostare la posa di Instance.Parent alla Fotogramma chiave.

Nota, questa funzione non darà errore quando un'istanza diversa da una Pose viene data come parametro di posa e la genitorerà con successo.

Parametri

pose: Instance

Il Pose da aggiungere.

Valore predefinito: ""

Restituzioni

()

Campioni di codice

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

Questa funzione restituisce un array che contiene tutti KeyframeMarkers che sono stati aggiunti al Keyframe.Nota, questa funzione restituirà solo instances di tipo KeyframeMarker.

Altro su Keyframes

Keyframe i nomi non devono essere unici.Ad esempio, se un'Animazione ha tre keyframe chiamati "Particelle" l'evento connesso restituito da AnimationTrack:GetMarkerReachedSignal() sarà attivato ogni volta che viene raggiunto uno di questi keyframe.

Keyframe i nomi possono essere impostati nell'Editor di animazione Roblox quando si crea o modifica un'animazioni.Non possono tuttavia essere impostati da un Script su un'animazione esistente prima di giocarci.

Vedi anche:


Restituzioni

Instances

Un array che contiene tutte le KeyframeMarkers che sono state aggiunte al Keyframe.

Campioni di codice

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

Questa funzione restituisce un array che contiene tutti Poses che sono stati aggiunti a un Keyframe .


Restituzioni

Instances

Un array di Poses .

Campioni di codice

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

()

Questa funzione rimuove un KeyframeMarker da Keyframe per le impostazioni il suo Instance.Parent a nil .

Il segnaposto KeyframeMarker Instance.Parent è impostato su nil ma non viene distrutto.Questo significa, a patto che il segnaposto sia referenziato, può essere ri-genitoriato in seguito.

Nota, questa funzione non darà errore quando un'istanza diversa da un KeyframeMarker viene data come parametro.

Altro su Keyframes

Keyframe i nomi non devono essere unici.Ad esempio, se un'Animazione ha tre keyframe chiamati "Particelle" l'evento connesso restituito da AnimationTrack:GetMarkerReachedSignal() sarà attivato ogni volta che viene raggiunto uno di questi keyframe.

Keyframe i nomi possono essere impostati nell'Editor di animazione Roblox quando si crea o modifica un'animazioni.Non possono tuttavia essere impostati da un Script su un'animazione esistente prima di giocarci.

Vedi anche:

Parametri

marker: Instance

Il segnaposto viene rimosso dalla Keyframe .

Valore predefinito: ""

Restituzioni

()

Campioni di codice

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

()

Questa funzione rimuove un Pose da Keyframe impostando il suo Instance.Parent a nil senza distruggerlo.Questo significa che la posa fornita è referenziata e può essere ri-genitori più tardi.

Nota, questa funzione non darà errore quando un'istanza diversa da una Pose viene data come parametro di posa.

Parametri

pose: Instance

Il Pose da rimuovere.

Valore predefinito: ""

Restituzioni

()

Campioni di codice

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

Eventi