Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Loading images quickly?

Asked by
saenae 318 Moderation Voter
9 years ago

I've finally gotten into the part of my game that requires loading assets, and I want to do so as efficiently as possible. I understand that there is a preload method, and it will likely be very helpful in the future for images that are to load after the loading screen goes away; however, I've found that some games load images as soon as the game starts without a problem. Having tried to do the same and having a couple friends test it out, mine take time to actually display. Am I missing something? If you guys have any experience in this area, I'd greatly appreciate the help! :)

0
Load the GUIs with ReplicatedFirst? alphawolvess 1784 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

The idea of pre loading is that all of the assets are loaded to the client before they are needed so that they are present when they are needed. This is why some GUI images are not present showing an incomplete GUI.

1st you need to add all of the assets to the pre loader 2nd create a loading screen and place it in the replicated first (or a script) 3rd update the loading screen according to the new value.

Here are some links to help loading screen content provider pre loader

Here is my current code I am using atm:- (local script)

local ContentProvider = game:GetService("ContentProvider")
local assetList = {55031729,55031700,48657647,67950784,67950809  --Gui song assets
    ,176828159, 221660385, 176827997, 172729074, 144947983, 222392802, 163353836, 222393264,172846809 } 
-- List of game assets


local function LoadAssets(AssetList)
    -- Takes an asset list and preloads it. Will not wait for them to load. 

    for _, AssetId in pairs(AssetList) do
        ContentProvider:Preload("rbxassetid://" .. AssetId)
        print("Added:-" .. AssetId)
    end
end

LoadAssets(assetList)

script.Parent:RemoveDefaultLoadingScreen()

local screen = Instance.new("ScreenGui")
screen.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local textLabel = Instance.new("TextLabel")
textLabel.Parent = screen
textLabel.Text = "Loading"
textLabel.Size = UDim2.new(1,0,1,0)
textLabel.FontSize = Enum.FontSize.Size14

local gameSize = game.ContentProvider.RequestQueueSize
local curSize = 0

while game.ContentProvider.RequestQueueSize > 0  do
    curSize = game.ContentProvider.RequestQueueSize
    if curSize < 0 then curSize = 0 end
    curSize = math.abs(gameSize - game.ContentProvider.RequestQueueSize)
    textLabel.Text = "Loading " .. gameSize .. "/" .. curSize
    print(textLabel.Text)
    wait()
end

while curSize < gameSize do
curSize = curSize +1
textLabel.Text = "Loading " .. gameSize .. "/" .. curSize
wait(1)
end

screen.Parent = nil

sorry its not commented it is a work in progress and demonstrates the basic usage of the loading screen.

Hope this helps

Ad

Answer this question