KeyframeMarker

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

鑰匙框標記是用於代表最終會被發射的事件的實例,當 Keyframe 被擊中時。

使用鑰匙框標記

鑰匙框架標記應該總是被設為鑰匙框架的父級,通過直接設置父級或使用鑰匙框架的 Keyframe:AddMarker() 函數來設置父級。鍵框標記也可以直接移除或使用 Keyframe:RemoveMarker() 函數來檢查哪些標記被附加到特定鍵框,並使用 Keyframe:GetMarkers() 來檢查哪些標記被附加到特定鍵框。

當鑰匙框被偵測為正在運行的動畫時,將會對每個鑰匙框標記發射事件,該標記與鑰匙框相關。這些事件可以透過 KeyframeMarker 的名稱進行識別。您可以使用 AnimationTrack.GetKeyframeMarkerReached 函數來檢索和聆聽這些事件。可選擇設置 KeyframeMarker.Value 鑰匙框標記的屬性,以便傳送具有事件發射的值。

它從 Keyframe.Name 繼承了 Instance 的屬性,並且行為相同。名稱用於識別,不需要獨一無二。當多個具有相同名稱的 KeyFrameMarkers 附加到 KeyFrame 時,事件,例如由 AnimationTrack:GetMarkerReachedSignal() 返回的事件,將對每個標記發射。

也見:

範例程式碼

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

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.

Listening to Keyframe Markers

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)

屬性

Value

平行讀取

指定給 KeyframeMarker 的值。當從 AnimationTrack:GetMarkerReachedSignal() 創建的信號被發射時,此值將傳到連接的函數中。

也見:

範例程式碼

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

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

方法

活動