So how would you guys implement a loading screen?

Hi again everyone!

So, when your game is loading up, there is sometimes a loading screen so you don’t have to look at a blank screen while it is loading up. You would usually have a loading bar that updates when a task in your loading process finishes. I don’t know if I should make a new thread for the loading screen or just draw it over everything until the game is all loaded. ???

If anyone has done something like this or has any idea on what I should do, then that would be great! :wink:

Thanks,
Longarmx

For this, you should load all your resources on a different Thread, and poll the progress of it.

It could also be done on the same thread – just update the progress bar GUI, then load the next resource, and repeat.

In terms of design, it will probably take a bit of refactoring if you haven’t organized your resource management at all.

polling is usually bad. Instead just send an event to the loading screen when the resources for it are ready.

Thank you everyone for your quick replies! I think that I will try to make it on the same thread, and then just update the loading bar when it reaches a certain point.

Thanks,
Longarmx

I support the use of polling. I prefer the idea of loading the resources in a different thread while the main game loop thread updates a loading bar based on how far the loading thread has completed.

What I’m curious about is how to determine the progress of the progress bar (lol). I mean, do you take, for example, all the resources you’ll load, let’s say 120 between images and sounds, then you’ll do 120 items / 100 % = 1.2, thus when loading one resources incrementing 1,2 of the progress bar??

I just realize that would be actually a good idea, right?


	private void loadEverything(){
		int incrementFactor = cantResources / 100;
		for(int i=0;i<cantImg;i++){
			loadImage("image"+i+".png");
			incrementProgressBar(incrementFactor);
		}
		for(int i=0;i<cantImg;i++){
			loadSould("sound"+i+".wav");
			incrementProgressBar(incrementFactor);
		}
	}

Edit: Added incrementFactor :slight_smile:

Or you do that calculation when you draw it on the screen. Here you simply increment the variable by 1.

Ideally it would be more like:
(with less verbose naming…)

//the size of our progress bar component
int width, height; 

//e.g. 3 images loaded out of 10, 30% finished
float progress = resourceManager.getLoadedCount() / resourceManager.getTotalResources();

//draw the "fill" bar stretched horizontally
progressBarFill.draw(x, y, progress*width, height);

//draw the outline so the user knows how much is remaining...
progressBarOutline.draw(x, y, width, height);

nah, you just would call directly the progress ( in %)

you don’t want to have the implementation how to calculate the progress in the open.
perhaps later you want to calc the progress relative to the file size of each resource and then perhaps give some hard to load resources a stronger weight.

Just use a xml which has all the paths and names for the images and load them deferred :slight_smile: After that I load them normally via a List which has all the deferred resssources and on render I show that in a nice big bar :o
This whole stuff does not happen in a different Thread… Why should I there is no reason because I just have images and some sounds. all 2D :slight_smile:

Or in noob way


//set display to loading screen
while (!done){
//load some stuffs
//update progress by one step
}

Actually would be my preference if only a loading bar is displayed. But as soon as you need to show something else moving around it don’t work so great anymore :slight_smile:

Loading animation? update it per frame on each step progress ;D

I just have the room manager draw a black rectangle over the screen until each object is ready for rendering; along with a little something in the bottom corner that moves so the player knows it’s working.

That’s just my over-simplicity talking though.