• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Loading Screen[SOLVED]

J

jr carey

Guest
so, ive been working on a game, and am in the need of a loading screen since it takes a while to generate these rooms, my texture page is small with the images only being 32x32, but I need a way to implement a loading screen, ive tried making a sprite, and throwing it into the room before doing the rest of my code, but the screen still turns up white for about 5-15 seconds, is there any way to make a loading screen?
 
J

jr carey

Guest
so heres how I solved it:

first you have to create a sprite and throw it onto the screen
then add a timer,
when that time is reached it should already be on the screen and you should finally be loading (you first have to load the loading image to show that your loading lol)
heres basically my code:

create:
loaded = false;
time = 0;

step:
if(instance_exists(obj_loading)){
time++;
if(loaded==false){
if(time>=60){ // any time will do, but don't forget its frame based, so in 60 frames it should be loading, imma drop this number down to like 5 or something
build_map();
time = 0;
loaded = true;
}
}
if(loaded==true){
with(obj_loading){
instance_destroy();
}
}
}

im gonna keep playing around with it, and I may have a better solution to this, but for now this is my option
 

TsukaYuriko

☄️
Forum Staff
Moderator
Ensure that a Draw event that will draw the graphics to the screen runs before your loading code runs. Placing an instance that has a sprite into a room won't do anything unless it gets to run its Draw event. A single frame has to render completely for this to show any effect.

If you want the loading to happen in parallel to whatever is going on in the loading screen, you have Async events at your disposal - at least on the platforms that support them being used that way. Apart from that, there have been a few attempts to implement multi-threading capabilities in GM games, with varying degrees of success, some of which are documented in the Tutorials forum - I suggest taking a look around there if this interests you.
 
I find it easier with an alarm. When I'm generating my map, I set a few things up in the Create Event:
Code:
loading = true;
load_step = 0;
load_string = "Picking island coastal points";
alarm[0] = 1;
This first alarm timer allows me to draw something on the screen before the load starts. Since you only need one step between any loop you have that is taking time, do not make the "timer" larger than 1, otherwise you are literally adding time to the load for no reason. Then in alarm[0], I setup a switch statement which determines what part of the load should be being run each step. Alarm[0]:
Code:
switch (load_step) {
   case 0:
 
       ds_list_clear(coastal_points_list);
       ds_queue_clear(fill_queue);
       load_string = "Smoothing island coastal points";
       etc...
   break;
   case 1:
      load_string = "Connecting island coastal points";
      etc...
   break;
}
load_step++;
alarm[0] = 1;
This make it so that on the first step, it executes all the code within the first case statement. Then on the next step, since load_step is increased by 1, it executes all the code within the second case statement and so on. I have my final case statement change the room to whatever the room is after I have finished loading (room_goto(rm_village) in my particular case). Finally, I have in the Draw GUI Event:
Code:
if (loading) {
   var gw = display_get_gui_width();
   var gh = display_get_gui_height();
   draw_set_color(c_black);
   draw_rectangle(0,0,gw,gh,false);
     
   draw_set_color(c_white);
   var load_dots = load_step;
   load_dots = load_dots mod 4;
   var str = load_string;
   repeat(load_dots) {
       str += ".";
   }
   var str_w = string_width(str)/2;
   draw_set_halign(fa_left);
   draw_set_font(fnt_menu_normal);
   draw_text(gw/2-str_w,gh/2,str);
}
This just covers the screen with a black rectangle (to hide any funny business going on that I might not want to be seen) and draws load_string in the middle of the screen, adding dots "." each step so that there is visible movement on the screen to confirm to the user that the load hasn't frozen. Unfortunately, since we don't have access to multithreading in GMS, it will still freeze while it is executing a particularly long loop (for instance, my height_map smoothing and cellular automata for forest growth both take a second or so to execute) but that is the best we are going to get in GMS right now.
 
Interesting, TsukaYuriko, I'll have to look into using the Async events you mentioned. My loading stuff was just what I made up as I was doing it, I didn't realise there was the potential for those (plus the multithreading attempts you mentioned) to be used.
 
Top