Making a progression bar
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Gunroar:Cannon()
- Party member
- Posts: 1131
- Joined: Thu Dec 10, 2020 1:57 am
Making a progression bar
How do I draw a progression bar that draws the progress of something that takes long to do(like loading a map) so that a player won't think the game has frozen? Do I use coroutines or what? I don't know so pls help...
Re: Making a progression bar
Do you load all data in one load/update tick?
- Gunroar:Cannon()
- Party member
- Posts: 1131
- Joined: Thu Dec 10, 2020 1:57 am
Re: Making a progression bar
So, you are need to load in multiple ticks.
- Gunroar:Cannon()
- Party member
- Posts: 1131
- Joined: Thu Dec 10, 2020 1:57 am
Re: Making a progression bar
Hmm, so draw as I go along? But can't I use coroutines or something?
PS: I noticed you added an avatar, nice.
PS: I noticed you added an avatar, nice.
-
- Prole
- Posts: 15
- Joined: Mon Oct 26, 2020 2:02 pm
Re: Making a progression bar
Just load a few objects at every update() instead of loading the whole thing.
Or create a corountine that loads the map and do a resume()/yield() after loading some amount of objects, do that untill everything is loaded.
Or create a corountine that loads the map and do a resume()/yield() after loading some amount of objects, do that untill everything is loaded.
Re: Making a progression bar
I think you can do this using Data objects, more specifically FileData, created by reading a file from disk with love.filesystem.newFileData.
FileData is a subclass of Data, so you can know the amount of bytes that the loaded file data represents. You can also calculate the total bytes from all assets that you're trying to load at a given moment while debugging your game (just remove that code for the release version, obviously). Then you know how many bytes you're trying to load at that moment, and how much each loaded asset represents of that total = a percentage for a progress bar.
You can create images from a FileData (FileData > ImageData > love.graphics.newImage overload that takes ImageData), and also audio (FileData > love.audio.newSource overload that takes a FileData), possibly others.
The only thing is how to asynchronously (i.e non-blockingly) load the FileData objects from files on disk. Lua coroutines are blocking (the ones that say they aren't, just yield() control back when there's no work to do). The only way is using the love.thread module, loading FileData objects in a thread, pushing them into a Channel and then popping from that Channel back on the main thread so that you can retrieve the FileData and use them to update the progress bar and read them into other LÖVE objects (images, audio etc).
So you can keep drawing animated graphics and updating the program while loading files in the background, on another thread.
FileData is a subclass of Data, so you can know the amount of bytes that the loaded file data represents. You can also calculate the total bytes from all assets that you're trying to load at a given moment while debugging your game (just remove that code for the release version, obviously). Then you know how many bytes you're trying to load at that moment, and how much each loaded asset represents of that total = a percentage for a progress bar.
You can create images from a FileData (FileData > ImageData > love.graphics.newImage overload that takes ImageData), and also audio (FileData > love.audio.newSource overload that takes a FileData), possibly others.
The only thing is how to asynchronously (i.e non-blockingly) load the FileData objects from files on disk. Lua coroutines are blocking (the ones that say they aren't, just yield() control back when there's no work to do). The only way is using the love.thread module, loading FileData objects in a thread, pushing them into a Channel and then popping from that Channel back on the main thread so that you can retrieve the FileData and use them to update the progress bar and read them into other LÖVE objects (images, audio etc).
So you can keep drawing animated graphics and updating the program while loading files in the background, on another thread.
Re: Making a progression bar
- Gunroar:Cannon()
- Party member
- Posts: 1131
- Joined: Thu Dec 10, 2020 1:57 am
Re: Making a progression bar
Can't I call the loading method in a coroutine and have value for progression of the loading that love.draw uses to draw the bar?
Re: Making a progression bar
Yes you can do that; you'd then need to yield after every asset is loaded.
You can also update the screen with love.graphics.present(), without using the update and draw callbacks. In that case you need to be careful to always call love.graphics.clear() to clear the screen before you draw the progress bar, though.
You can also update the screen with love.graphics.present(), without using the update and draw callbacks. In that case you need to be careful to always call love.graphics.clear() to clear the screen before you draw the progress bar, though.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests