Game Maker games rarely needs any loading time once the game is started. Sounds and graphics goes by an instant, for which reason you will never have to implement loading bars such as commercial games often have to show the progress while loading graphics and sounds for the next level or similar. However, there are situations where you need to go through a lot of data. I once made a program where I had to check 22 0000 values and write them to the registry. That took a long time. If I had not had a loading bar during that process chances are big my users would have closed the window by alt+ctrl+delete as Game Maker makes the window to appear frozen, when using loops as I did.
Loops are the absolute fastest method to do when doing these kinds of things, but there is one big problem. While a loop is working no other code may be executed, therefore no step will be taken and the user cannot get any response from the game. The only way to show the user that the game is still working is therefore, to do like I propose here.
<b>The solution is to have a variable that updates the progress from within the loop.</b> You will have initialized the variable on beforehand and in the loop simply add one to it each time. Then in draw event you have prepared a code to draw that variable. But this is not enough. Since no step will be taken while within the loop, the number that is drawn based on the variable will not be updated.
This can be fixed by screen_refresh(). The code you need is therefore the following:
//Create
var_i = 0;
//Loop:
for (s=0; s<20000; s+=1) {
Custom code
var_i +=1;
screen_refresh();
}
//Draw event:
draw_text(x,y,string(var_i));
If you want this in a loading bar the percentage could easily be calculated like this; var_i/20000 (where 20000 should be replaced by the total number).
Anything else you want to know, just ask.
.
Users logged in:
Comments
Loading comments...