PreloadAsync

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.


https://developer.roblox.com/en-us/api-reference/function/ContentProvider/PreloadAsync


local ContentProvider = game:GetService("ContentProvider")


-- Create some objects to be preloaded

local sound = Instance.new("Sound")

sound.SoundId = "rbxassetid://1838058421"

local decal = Instance.new("Decal")

decal.Texture = "rbxassetid://5447528495"


-- A table of various assets to preload (Instances or content)

local assets = {

decal,

sound,

"rbxassetid://5173222739",

"rbxthumb://type=Avatar&w=100&h=100&id=269323"

}


-- For demonstration, pre-load 50 random user's avatar thumbnails

for i = 1, 50 do

table.insert(assets, "rbxthumb://type=Avatar&w=100&h=100&id=" .. math.random(1,1000000))

end


-- Preload the content and time it

local startTime = os.clock()

ContentProvider:PreloadAsync(assets)

local deltaTime = os.clock() - startTime

print(("Preloading complete, took %.2f seconds"):format(deltaTime))

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容