KeyframeMarker
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
เครื่องหมายกรอบสําคัญคือตัวอย่างที่มีจุดมุ่งหมายเพื่อแทนที่เหตุการณ์ที่จะถูกยิงในที่สุดเมื่อ Keyframe ถูกโจมตี
ใช้เครื่องหมายกรอบสําคัญ
เครื่องหมายกรอบสําคัญควรจะเป็นพ่อของ Keyframe เสมอโดยการตั้งค่าพ่อโดยตรงหรือโดยใช้ฟังก์ชัน Keyframe:AddMarker() ของ Keyframeเครื่องหมายกรอบสําคัญยังสามารถลบได้โดยตรงหรือโดยใช้ฟังก์ชัน Keyframe:RemoveMarker() และสอบถามเพื่อตรวจสอบว่าเครื่องหมายใดที่แนบมากับ Keyframe เฉพาะโดยใช้ Keyframe:GetMarkers()
เมื่อมีการตรวจพบกรอบสําคัญเป็นภาพเคลื่อนไหว จะมีการเรียกการเหตุการณ์สําหรับแต่ละ KeyframeMarker ที่เป็นพ่อของกรอบสําคัญเหตุการณ์เหล่านี้สามารถระบุได้โดยชื่อของ KeyframeMarkerคุณสามารถดึงและฟังเหตุการณ์เหล่านี้โดยใช้ฟังก์ชัน AnimationTrack.GetKeyframeMarkerReachedตัวเลือกคุณสามารถตั้งค่าคุณสมบัติ KeyframeMarker.Value ของ KeyframeMarker เพื่อส่งมอบค่าที่มีการยิงเหตุการณ์
มันมีลักษณะที่สืบทอดคุณสมบัติ Keyframe.Name จาก Instance และมีพฤติกรรมเหมือนกันชื่อใช้สำหรับการระบุตัวตนและไม่จำเป็นต้องเป็นเอกลักษณ์เมื่อมีหลายตัวอย่าง KeyframeMarker ที่มีชื่อเดียวกันแนบมากับ Keyframe เหตุการณ์เช่นหนึ่งที่ถูกส่งกลับโดย AnimationTrack:GetMarkerReachedSignal() จะเกิดขึ้นสำหรับแต่ละเครื่องหมาย
ดูเพิ่ม:
- , เก็บ แอนิเมชัน
- Animation จัดเก็บการอ้างอิงถึงข้อมูลแอนิเมชันที่จำเป็นสำหรับการเล่นแอนิเมชันกำหนดเองบนตัวละครหรือรูปแบบอื่นโดยใช้ระบบแอนิเมชันของ Roblox
ตัวอย่างโค้ด
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)
สรุป
คุณสมบัติ
มูลค่าที่กำหนดสำหรับ KeyframeMarker ที่ระบุ
คุณสมบัติ
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.
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