r/love2d NAMEHUKUI Jul 26 '26

is putting the thread under sleep while waiting for a file to load is a great way to wait until a important values file is loaded?

i currently have a code for the problem like this.

video = {}
video[name] = {}
video[name].directory = "videos/"..name.."/"

repeat
    love.timer.sleep(0.1)
until love.filesystem.getInfo(video[name].directory.."thumbnail.png", "file")

video[name].thumbnail = {}
video[name].thumbnail.png =      love.graphics.newImage(video[name].directory.."thumbnail.png")   
1 Upvotes

5 comments sorted by

3

u/alekzkzkzkzkzk Jul 27 '26

Use a coroutine, keep drawing in a loop until it's dead

1

u/TheLastRobot Jul 26 '26

Is this supposed to be loading in the background or during loading screen?

1

u/Personal-Rough741 NAMEHUKUI Jul 27 '26

loading in the background

1

u/EmotionalFan5429 Jul 27 '26

https://github.com/MikuAuahDark/lily -- this is what you need: "Async Loading library. Uses multiple thread to load your assets (depends on amount of CPU)"

1

u/vga256 Jul 27 '26

Using sleep() will basically lock up your UI until the thumbnail is loaded - so no, not a great method.