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

How do I improve the performance of my .gif GUI with 70 images (1 frame per 0.04 second)?

Asked by
Seraine 103
7 years ago

This is a section of the script, altogether there's 70 images. At the moment the images keeps on flashing because of latency, it also freezes and then plays perfectly for a split second and then flashes again. Is there anyway I can make it so the images change without flashing?

while true do
    wait(0.04)
    script.Parent.Image = "rbxassetid://544664857"--0
    wait(0.04)
    script.Parent.Image = "rbxassetid://544665861"--1
    wait(0.04)
    script.Parent.Image = "rbxassetid://544666597"--2
end

Here's the place with the .gif GUI: https://www.roblox.com/games/544685431/Seraines-Place-Number-40

Thanks

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

wait() isn't very precise, especially with very short times. You need to use a delta time loop to handle this.

Additionally, the only way to combat the latency is to script this using a LocalScript.

local frames = {
    {img = 544664857, rate = .04};
    {img = 544665861, rate = .04};
    {img = 544666597, rate = .04};
}

--EDIT - yep, I forgot to have the images preloaded! Let's fix that here:
do
    local ContentProvider = game:GetService("ContentProvider")
    local images = {}
    for _, v in ipairs(frames) do
        table.insert(images, "rbxassetid://" .. v.img)
    end
    ContentProvider:PreloadAsync(images)
end
--

local GUI = script.Parent

local RenderStepped = game:GetService("RunService").RenderStepped
local i = 1
local extra = 0
while true do
    GUI.Image = "rbxassetid://" .. frames[i].img
    local st = tick() + extra

    while true do
        RenderStepped:wait()
        local t = tick()
        if t - st >= frames[i].rate then
            extra = t - st - frames[i].rate
            break
        end 
    end

    i = (i + 1)%(#frames + 1)
end

Delta time usage is a confusing concept to understand, so definitely ask any questions you have about it!

Some references that may be helpful:

1
You forgot to account for the fact that the frames aren't preloaded. User#6546 35 — 7y
0
Yeah the gif doesn't play ;c Seraine 103 — 7y
0
Thanks for you help, but the loop stops after every frame has been played, you can see it here: https://www.roblox.com/games/544685431/Seraines-Place-Number-40 Seraine 103 — 7y
Ad

Answer this question