Loading Bar
by Bruno · in Torque Game Builder · 11/03/2009 (7:13 pm) · 8 replies
Hello,
I'm tryng to make a loading bar to show the loadig progress.
To do so, i have a diferent GUI, where i have a loading bar, that i change size while the game loads.
I use the usual levelManagement.cs that comes by default with TGB to load my level.
"barra" is the name of a image in the gui.
In it, i do the following :
[src]
for (%i = 0; %i < %sceneObjectCount; %i++)
{
%sceneObject = getWord(%sceneObjectList, %i);
%sceneObject.onLevelLoaded(%scenegraph);
if(%i == %sceneObjectCount / 5)
{
Canvas.setContent(load_screenGUI);
barra.Extent = "270 32";
Canvas.repaint();
}
if(%i == %sceneObjectCount / 4)
{
Canvas.setContent(load_screenGUI);
barra.Extent = "350 32";
Canvas.repaint();
}
[\src]
The problem with this, is that it seems anything i do with the Canvas inside the t2dSceneWindow::loadLevel(%sceneWindow, %levelFile) doens't work.
Am i doing something wrong here ?
If i use this in any other part of the game, works just fine.
thanks,
Bruno
I'm tryng to make a loading bar to show the loadig progress.
To do so, i have a diferent GUI, where i have a loading bar, that i change size while the game loads.
I use the usual levelManagement.cs that comes by default with TGB to load my level.
"barra" is the name of a image in the gui.
In it, i do the following :
[src]
for (%i = 0; %i < %sceneObjectCount; %i++)
{
%sceneObject = getWord(%sceneObjectList, %i);
%sceneObject.onLevelLoaded(%scenegraph);
if(%i == %sceneObjectCount / 5)
{
Canvas.setContent(load_screenGUI);
barra.Extent = "270 32";
Canvas.repaint();
}
if(%i == %sceneObjectCount / 4)
{
Canvas.setContent(load_screenGUI);
barra.Extent = "350 32";
Canvas.repaint();
}
[\src]
The problem with this, is that it seems anything i do with the Canvas inside the t2dSceneWindow::loadLevel(%sceneWindow, %levelFile) doens't work.
Am i doing something wrong here ?
If i use this in any other part of the game, works just fine.
thanks,
Bruno
About the author
#2
Also, is there a reason why you need a loading bar? I've yet to see any level that takes more than a millisecond to load.
Finally, by the time you are in the for-loop, the level has already been loaded. That loop just notifies all of the objects in the scene that the level has been loaded.
11/04/2009 (8:00 pm)
The for-loop that you are in will completely finish before any of the GUIs modified inside of it has a chance to update themselves.Also, is there a reason why you need a loading bar? I've yet to see any level that takes more than a millisecond to load.
Finally, by the time you are in the for-loop, the level has already been loaded. That loop just notifies all of the objects in the scene that the level has been loaded.
#3
Where are the resources being loaded then ?
Any advice to where i should look at ?
The levels in question are quite big, and altough in my machine they load quite fast, in lower-end machines it takes some time.
thanks,
Bruno
11/05/2009 (12:20 am)
Thanks William,Where are the resources being loaded then ?
Any advice to where i should look at ?
The levels in question are quite big, and altough in my machine they load quite fast, in lower-end machines it takes some time.
thanks,
Bruno
#4
How many objects are in your scene file? Could some of them be created in script just before they are needed?
11/05/2009 (12:40 am)
The real work gets done in levelManagement.cs's t2dSceneGraph::addToLevel function. The file is loaded by using the built-in "exec(%levelFile);" call. This compiles the ".t2d" file and loads it in all at once. There isn't really a way to load in a file piece by piece.How many objects are in your scene file? Could some of them be created in script just before they are needed?
#5
I have an average of 200 objects in each level.
There must be a way to do this, a exec(%levelFile) just compiles a script, doens't actually load the level itself ( i think ).
11/05/2009 (12:43 am)
Nahh, they can't be created in script, I have an average of 200 objects in each level.
There must be a way to do this, a exec(%levelFile) just compiles a script, doens't actually load the level itself ( i think ).
#6
If you are feeling adventurous, you could modify "t2dSceneWindow::loadLevel" so that it takes an "append" parameter which makes it so the level file is appended to the current scene. You'll have to split up your level files into multiple files. You'll also have to put the "loadLevel" call on a schedule so that you can have a loading bar.
How long does it take to load on these lower-end machines? If it's just a second or two, I wouldn't sweat it. Pop up a "LOADING" screen, and schedule the level to load.
11/05/2009 (3:09 am)
The function "exec" both compiles and executes a script. Level files are just a list of objects to get new'd up. Thus, when you "exec" it, it'll execute all of the "new"s.If you are feeling adventurous, you could modify "t2dSceneWindow::loadLevel" so that it takes an "append" parameter which makes it so the level file is appended to the current scene. You'll have to split up your level files into multiple files. You'll also have to put the "loadLevel" call on a schedule so that you can have a loading bar.
How long does it take to load on these lower-end machines? If it's just a second or two, I wouldn't sweat it. Pop up a "LOADING" screen, and schedule the level to load.
#7
I got it working perfectly, but in another way.
Doing it as you are suggesting, would be a pain, lol
So, what i ended up doing, is finding in the engine source, where the images are being loaded, and inside that function, i execute a script function, and on that script function i update the loading bar.
Works great :)
Something like this :
[src]
bool t2dImageMapDatablock::loadSrcBitmap( void )
{
// Have we a source bitmap?
if ( !mpSrcBitmap )
{
Con::executef( 2, "UpdateLoadingBar", 0 );
[/src]
I don't know how much it takes in the lower-end machines, if it was me i would leave it like this, but it's a requirement from my publisher.
thanks,
Bruno
11/05/2009 (1:25 pm)
Thanks again William ;)I got it working perfectly, but in another way.
Doing it as you are suggesting, would be a pain, lol
So, what i ended up doing, is finding in the engine source, where the images are being loaded, and inside that function, i execute a script function, and on that script function i update the loading bar.
Works great :)
Something like this :
[src]
bool t2dImageMapDatablock::loadSrcBitmap( void )
{
// Have we a source bitmap?
if ( !mpSrcBitmap )
{
Con::executef( 2, "UpdateLoadingBar", 0 );
[/src]
I don't know how much it takes in the lower-end machines, if it was me i would leave it like this, but it's a requirement from my publisher.
thanks,
Bruno
#8
Best of luck!
11/05/2009 (2:24 pm)
I'm glad you found a solution! If you have it there, it looks like your problem might be a lot of images. I'll have to keep that location in mind for my next project!Best of luck!
Torque Owner Bruno