KeyframeSequenceProvider
*Pronto este contenido estará disponible en tu idioma seleccionado.
The KeyframeSequenceProvider service provides functions to load and preview KeyframeSequences. It includes a number of functions that are useful when working with Animations.
A KeyframeSequence stores a series of Poses that encode the hierarchy and motion of an animation. The animation data Roblox uses in the playback of an animation, referenced by the Animation.AnimationId property, can be constructed from a KeyframeSequence. KeyframeSequences are usually created by the Roblox Animation Editor but can be created through other plugins or even manually.
Muestras de código
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local function createPreviewAnimation(keyframeSequence)
local hashId = KeyframeSequenceProvider:RegisterKeyframeSequence(keyframeSequence)
local Animation = Instance.new("Animation")
Animation.AnimationId = hashId
return Animation
end
local keyframeSequence = Instance.new("KeyframeSequence")
local animation = createPreviewAnimation(keyframeSequence)
print(animation)
Resumen
Métodos
Generates a temporary asset ID from a KeyframeSequence that can be used for localized testing of an animation. Generates an active:// URL.
Generates a temporary asset ID from a KeyframeSequence that can be used for localized testing of an animation. Generates a hash.
This function returns an InventoryPages object which can be used to iterate over animations owned by a specific user.
Returns a KeyframeSequence based on the specified assetId asynchronously.
Propiedades
Métodos
RegisterActiveKeyframeSequence
Generates a temporary asset ID from a KeyframeSequence that can be used for localized testing of an animation.
This function performs the same function to KeyframeSequenceProvider:RegisterKeyframeSequence() however this function generates an active:// URL instead of a hash.
The ID generated can be used in an Animation.AnimationId property for testing.
The asset ID generated by this function is temporary and cannot be used outside of Studio. Developers wishing to generate an asset ID that can be used online should upload the KeyframeSequence to Roblox.
Parámetros
The KeyframeSequence to be used.
Devuelve
A temporary asset ID generated for localized animation playback.
Muestras de código
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local function createPreviewAnimation(keyframeSequence)
local hashId = KeyframeSequenceProvider:RegisterKeyframeSequence(keyframeSequence)
local Animation = Instance.new("Animation")
Animation.AnimationId = hashId
return Animation
end
local keyframeSequence = Instance.new("KeyframeSequence")
local animation = createPreviewAnimation(keyframeSequence)
print(animation)
RegisterKeyframeSequence
Generates a temporary asset ID from a KeyframeSequence that can be used for localized testing of an animation.
This function performs the same function to KeyframeSequenceProvider:RegisterActiveKeyframeSequence() however this function generates a hash instead of an active:// URL.
The ID generated can be used for the Animation.AnimationId property to test animations.
The asset ID generated by this function is temporary and cannot be used outside of Studio. Developers wishing to generate an asset ID that can be used online should upload the KeyframeSequence to Roblox.
Parámetros
The KeyframeSequence to be used.
Devuelve
A temporary asset ID generated for localized animation playback.
Muestras de código
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local asset = KeyframeSequenceProvider:RegisterKeyframeSequence(workspace.KeyframeSequence)
local animation = Instance.new("Animation")
animation.Name = "TestAnimation"
animation.AnimationId = asset
animation.Parent = workspace
GetAnimations
This function returns an InventoryPages object which can be used to iterate over animations owned by a specific user.
This function has a number of potential uses, such as allowing users to browse and import animations into a custom animation plugin.
Parámetros
The user ID of the user.
Devuelve
An InventoryPages of animations.
Muestras de código
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local USER_ID = 0 -- Insert your UserId here
local function extractPages(pagesObject)
local array = {}
while true do
local thisPage = pagesObject:GetCurrentPage()
for _, v in pairs(thisPage) do
table.insert(array, v)
end
if pagesObject.IsFinished then
break
end
pagesObject:AdvanceToNextPageAsync()
end
return array
end
local inventoryPages = KeyframeSequenceProvider:GetAnimations(USER_ID)
local animationIds = extractPages(inventoryPages)
for _, id in pairs(animationIds) do
print(id)
end
print("total: ", #animationIds)
GetKeyframeSequenceAsync
GetKeyframeSequenceAsync returns a KeyframeSequence based on the specified assetId. The assetId must correspond to an animation. The function will yield until the KeyframeSequence is loaded from the website. Because this is a webcall it should wrapped in a pcall.
Parámetros
The content ID of the animation.
Devuelve
The KeyframeSequence found.
Muestras de código
local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local ANIMATION_ID = "rbxassetid://507771019"
-- Get the keyframe sequence for the asset
local keyframeSequence
local success, err = pcall(function()
keyframeSequence = KeyframeSequenceProvider:GetKeyframeSequenceAsync(ANIMATION_ID)
end)
if success then
-- Iterate over each keyframe and print its time value
local keyframeTable = keyframeSequence:GetKeyframes()
for key, value in keyframeTable do
print(`The time of keyframe number {key} is: {value.Time}`)
end
else
print(`Error getting KeyframeSequence: {err}`)
end