Loading a World behind the Menu
A second fairly simple enhancement that we can do to our menus is load a world behind the menu form. The simplest way to do this is simply call the 'StartLoadingWorld()' function somewhere in your MenuStartup() function, like so:
void MenuStartup()
{
// show splash screen before the menu
LoadBackdrop( "splashscreen.psd");
Delay(3);
// load world behind menu
StartLoadingWorld( "../worlds/menu.wld");
LoadBackdrop( "menu_main.psd");
ShowForm( "MainMenu");
}
If you test your game, you will see the world that you specify behind your menu now, and you'll also notice that even though we have the LoadBackdrop() and ShowForm() function calls AFTER the StartLoadingWorld() function, the main menu displays while the game is still loading.
This is because game scripts in GameCore are processed top to bottom, unless you have some kind of logic statement to pause the script or otherwise break up the processing of the script.
Another thing to note is that the backdrop 'menu_main.psd' does NOT show up if you load a world that contains a sky or otherwise fills the screen - this is because Backdrops are rendered behind the World. You can use this to your advantage however by providing a pre-rendered background to show behind your world, or a graphic etc that otherwise is shown behind whatever 3d objects you might load into your menu.
You will also notice (depending on the size of the world you are loading behind the menu) that the game will seem like it has stopped responding to input (or seem very laggy) while the world is loaded. We'll address this in the next section.
Adding a Loading Screen & Progress Bar
The default script as defined in the Loading a World section includes a loading screen when you load a world. We can add this to our menu script as well, to show a loading screen prior to the game menu being displayed. It is a good idea to give your users some feedback while anything is happening, whether loading a world or otherwise doing some kind of processing that may take a while to do.
ShowForm( "LoadingScreen");
StartLoadingWorld( "../worlds/world.wld");
while (!DoneLoadingWorld())
Delay( 0.001f);
HideForm( "LoadingScreen");
All this script snippet does is show our LoadingScreen form while the world is loading, and adds a 'while' loop while the world is loading. GameCore provides a DoneLoadingWorld() function that returns true when the world is completed loading, so we can loop while it's 'not' done loading the world, and show our LoadingScreen in the meantime.
void MenuStartup()
{
// show splash screen before the menu
LoadBackdrop( "splashscreen.psd");
Delay(3);
// load world behind menu
ShowForm( "LoadingScreen");
StartLoadingWorld( "../worlds/world.wld");
while (!DoneLoadingWorld())
Delay( 0.001f);
HideForm( "LoadingScreen");
LoadBackdrop( "menu_main.psd");
ShowForm( "MainMenu");
}
The LoadingScreen form is defined in the menu.lay file, and can be customized for your own game as desired, by providing a custom progress bar graphic, text and so on.
You could also add a seperate 'loading' screen backdrop prior loading your world as well, again this is a one-line enhancement
void MenuStartup()
{
// show splash screen before the menu
LoadBackdrop( "splashscreen.psd");
Delay(3);
// load world behind menu
LoadBackdrop( "loadingmenu.psd");
ShowForm( "LoadingScreen");
StartLoadingWorld( "../worlds/world.wld");
while (!DoneLoadingWorld())
Delay( 0.001f);
HideForm( "LoadingScreen");
LoadBackdrop( "menu_main.psd");
ShowForm( "MainMenu");
}
Setting up the Camera
If you've been following along and test your game at this point (or any point along the way), you'll notice that our world doesn't properly show up - well at least it doesn't show up the way that we want it to. This is because we haven't defined any kind of camera for the viewport to show.
By default, the camera will simply be dropped at 0,0,0 and won't likely show anything interesting, unless you fluke out and it does ;}
For my menu I want to be able to setup a number of different camera angles and potentially have them switch between while the menu is active. For your own menu, you can use any of the techniques described in the Cinematic tutorials to build the view behind your menu, whether static cameras, dynamic cameras, full-blown cinematic flythrough or machinima movie combining all three techniques.
In order to setup a camera angle, first we need to grab a handle to the viewport (screen), in order to define the camera position & setup.
This is done using the following script:
Viewport @ viewport = GetGameManager().GetViewport( "Main");
Every GameCore game has a primary / default viewport called 'Main'. You can have multiple viewports active at any point, and could theoretically have multiple views in your world active behind the menu as well.
For this demo, we'll simply use a single viewport and then setup the camera for this viewport.
After adding the above lines, our MenuStartup function looks like so:
void MenuStartup()
{
// splash screen 1
LoadBackdrop( "gdgi.psd");
Delay(3);
// load world behind menu
StartLoadingWorld( "../worlds/menu.wld");
ShowForm("LoadingScreen");
while (!DoneLoadingWorld())
Delay( 0.001f);
HideForm("LoadingScreen");
Viewport@ viewport = GetGameManager().GetViewport( "Main");
ShowForm( "MainMenu");
}
Now that we have a pointer to the main viewport (the full screen), we can begin setting camera angles for the viewport.
First, move, rotate or otherwise position the camera where you want it to be and click the Cinema menu, then 'Copy Camera Position'
Clicking Copy Camera Position copies the Editor's camera's Position, Target & Field of View to the clipboard, so you can simple paste it into your game script. (press ctrl->v or right click & paste). GameCore will even write the necessary script snippet for you!
You can see the results of my 'paste' below, and the updated MenuStartup function:
void MenuStartup()
{
// splash screen 1
LoadBackdrop( "gdgi.psd");
Delay(3);
// load world behind menu
StartLoadingWorld( "../worlds/menu.wld");
ShowForm("LoadingScreen");
while (!DoneLoadingWorld())
Delay( 0.001f);
HideForm("LoadingScreen");
GameManager@ game = GetGameManager();
Viewport@ viewport = game.GetViewport( "Main");
viewport.SetCameraPos( -5.845, 8.904, -5.420);
viewport.SetCameraTarget( 0.446, 6.071, 0.407);
viewport.SetCameraFOV( 60.000);
ShowForm( "MainMenu");
}
The Final Result
That's it!
Printer-friendly version- Login to post comments
- PDF version
