- Online Community Forums » Programming Questions » How to make a loading screen?

This thread is locked; no one can reply to it. rss feed Print
How to make a loading screen?
Member #13,811
December 2011

I'm making an RPG game and the map is 10000 pixels by 10000 pixels(One of the maps I should say) and on my computer it takes about 1-3 seconds to load, but on my girlfriends laptop it takes about 6-8 seconds and I was just wondering if it was able to make a loading screen. So that you didn't just have to look at black, I did think of other ways of doing it, like only loading 640, 480 pixels around you as you walk but I just thought that it would be nice to learn something new today if it's not to much trouble for you to explain how I would go about doing that.
Thank-you ;D

Edgar Reynaldo
Major Reynaldo
May 2007

Member #8,381
March 2007

It can be done even without I suppose, although depending on the loading method. You may split loading work to multiple smaller ones and update the animation in between them.

However, majority of simple applications just show a loading image for that purpose. This way you just first load & display small image and then load the heavy stuff.

Member #13,811
December 2011

Could any of you give me some example code, or point me to a web site that teaches me what I need to know. It would be much appreciated :)

Matthew Leverton
Supreme Loser
January 1999

With Allegro 5.0:

1// mark as volatile so that the compiler knows it may unexpectedly change 2volatile bool done_loading = false; 3ALLEGRO_BITMAP *my_bitmap; 4 5void *my_thread(ALLEGRO_THREAD *me, void *data) 6{ 7 (void) data; // aren't using this. this is the NULL parameter from below 8 9 my_bitmap = al_load_bitmap("foo.bmp"); 10 // load other bitmaps 11 12 done_loading = true; 13 14 // when running an attached thread, the following is the return value to 15 // al_join_thread(), which we are not using here. 16 return NULL; 17} 18 19// starts the loading thread 20al_run_detached_thread(my_thread, NULL); 21 22// this code will execute while the above function is running 23 24while (!done_loading) 25{ 26 // show loading page, etc 27}

Normally you'd need to convert the bitmap to video after that while loop is over because the loader thread will create it as memory. However, in your case, the video card is not going to support a video bitmap of that size, so it doesn't matter. (But if you are loading smaller bitmaps, you'd need to convert them to video.)

Threading can get complex because you normally don't want two threads reading and writing the same data at the same time. However in this case, since one thread is writing a boolean that the other thread only reads, it will be safe. For more complex interaction, you need to use mutexes and condition variables.

Anyway, all that said, the real solution is not to use a bitmap that large...

Member #12,636
March 2011

Agreed there, I think you should look into using tile maps, in stead of using such a huge background image.

Go to: