KeyframeMarker
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Un KeyframeMarker è un'istanza destinata a rappresentare un evento che verrà infine attivato quando viene colpito un Keyframe .
Utilizzo di un KeyframeMarker
I segnapunti Keyframe dovrebbero sempre essere genitori di un Keyframe tramite l'impostazione del genitore direttamente o usando la funzione Keyframe:AddMarker() di Keyframe.I segnapunti Keyframe possono anche essere rimossi direttamente o utilizzando la funzione Keyframe:RemoveMarker(), e interrogati per verificare quali segnapunti sono allegati a un Keyframe specifico utilizzando Keyframe:GetMarkers().
Ogni volta che un Keyframe viene rilevato come un'animazione in esecuzione, verrà attivato un evento per ogni KeyframeMarker che è parented al Keyframe.Questi eventi sono identificabili dal nome del KeyframeMarker.Puoi recuperare e ascoltare questi eventi utilizzando la funzione AnimationTrack.GetKeyframeMarkerReached.Opzionalmente, puoi impostare la proprietà KeyframeMarker.Value della KeyframeMarker per trasmettere un valore con l'evento innescato.
Eredita la proprietà Keyframe.Name da Instance e si comporta identicamente.I nomi vengono utilizzati per l'identificazione e non devono essere unici.Quando più KeyframeMarker istanze con lo stesso nome sono allegate a un Keyframe , eventi come quello restituito da AnimationTrack:GetMarkerReachedSignal() saranno attivati per ogni marcatore.
Vedi anche:
- Animation , contiene un riferimento ai dati di animazione richiesti per riprodurre animazioni personalizzate su personaggi o altri modelli utilizzando il sistema di animazione Roblox
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.
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
This LocalScript code waits for the local player's Humanoid object to load, then it creates a new Animation instance with the proper Animation.AnimationId. The animation is then loaded onto the humanoid, creating an AnimationTrack, and the track is played with AnimationTrack:Play(). Following that, the AnimationTrack:GetMarkerReachedSignal() function detects when the "KickEnd" marker is hit.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.Character:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Create new "Animation" instance
local kickAnimation = Instance.new("Animation")
-- Set its "AnimationId" to the corresponding animation asset ID
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- Load animation onto the humanoid
local kickAnimationTrack = humanoid:LoadAnimation(kickAnimation)
-- Play animation track
kickAnimationTrack:Play()
-- If a named event was defined for the animation, connect it to "GetMarkerReachedSignal()"
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)
Proprietà
Value
Un valore che viene specificato per un KeyframeMarker .Ogni volta che il segnale creato da AnimationTrack:GetMarkerReachedSignal() viene sparato, questo valore verrà passato alla funzione connessa.
Vedi anche:
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.
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
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