Demo
In this document you will how use the EGE system.
We use a multi-step thread that allow use to wait asynchronous process to make sure everything is loaded.
This example is take from the Do Not Answer (Alpha 0.0.1) - Main Menu.
Download file:
Initialization
The first thing we do is calling all module from EE than we going to need then we call the EE.LaunchGE() function and as a callback out main thread (See bellow).
- EE0_3.Call(EE0_3.modulesList.UTIL_LOADCHECK, function(){
- EE0_3.Call(EE0_3.modulesList.ARRAY_GRID2D, function(){ //Launching Game Engine
- EE0_3.LaunchGE("#CreatorDiv", [EE0_3.EGEModulesList.GUI_OVERLAY, EE0_3.EGEModulesList.GUI_WIDGET, EE0_3.EGEModulesList.GUI_WIDGET_BUTTON, EE0_3.EGEModulesList.GUI_WIDGET_TEXT, EE0_3.EGEModulesList.LOADING_LOADING], MainThread);
- });
- });
Global Variable
We also use global variable to store global data:
- //Main thread globla variable
- menu_OverallLoading;
- mainOverlay = null;
- //Widgets
- menu_text = null;
- menu_button = null;
Main Thread
Now we use multi-step thread function: we will call all functionality we want to add and each widgets we want to create to initialize the app, and each time we need something to load (A module, an image, etc..), as callback function we use the step function we an incremented step ID.
Step undefined or null
The first step is not 0 but nothing (undefined) but it is working like any other step:
- function MainThread(EGE, Step){
- if(Step == undefined || Step == null){
- //Creating loading
- creator_OverallLoading = EGE.AddOverAllLoading();
- creator_OverallLoading.AddLoadingBar(function(){ MainThread(EGE, 0); });
- }
First thing we do here is to create a loading system it will show a loading bar over everything (so the EGE can work behind and also show the progress to the user). We store this last into a global variable then call AddLoadingBar(), this function has to load an EE module so we wait the loading is over by send an lambda function with our main thread function and as parameter the EGE ref and the next index which is 0.
Step 0
- if(Step == 0){
- //Creating loading
- creator_OverallLoading.SetMaxStep(4);
- creator_OverallLoading.SetLoadingBackColor("#000000");
- creator_OverallLoading.SetLoadingFrontColor("#ffffff");
- creator_OverallLoading.SetBackgroundHex("#7f7f7f");
- creator_OverallLoading.Launch(function(){ MainThread(EGE, 1); });
- }
In this step we set details about our loading system like how step will be used (See SetMaxStep and Step functions), the bar color, the background color and then we Launch the loading, it will now appear and be ready to use, of as you might noticed I've called the thread function with index 1.
Note: the loading system is an information display, it goes over everything.
Step 1
- if(Step == 1){
- //Setting up GameEngine
- EGE.SetFullscreen(function(){ MainThread(EGE, 2); });
- }
This step is a way more lighter, we just the fullscreen button on, but since it has to wait images to load we pass the thread again with index 2.
Step 2
- if(Step == 2){
- creator_OverallLoading.Step();
- //Creating main overlay
- mainOverlay = EGE.GUI.AddNewMenuOverlay("mainOverlay");
- //Setting Up Main Overlay
- mainOverlay.IsFillingViewport(true);
- mainOverlay.SetBackgroundImage("Src/BG/BGI_MenuBackground.png", function(){ MainThread(EGE, 3); });
- }
First we add step in the loading system to make the bar moving. Then we create our main overlay named: "mainOverlay" so every children IDs will start by mainOverlay_.
Then we start calling setters for our mainOverlay the important IsFillingViewport and we set the background image and wait for it to load.
Step 3
The step is a long step in our initialization and the final one, for easier explanation I've separated in two:
- if(Step == 3){
- //Creating main overlay
- creator_OverallLoading.Step();
- //Adding text
- menu_text = mainOverlay.AddWidget(EGE.GUI.WidgetType.WIDGET_TEXT, "Menu_Text").SetSizePosition("100%", "4vw", 0, "calc(50% - 6vw)").AddText("Welcom in <span style=\"text-decoration: underline;\">Do Not Answer</span> for the moment only the creator is available.").TextAlign("Centered", "Centered").SetFontSize("2vw");
- creator_OverallLoading.Step();
- //Adding button
- menu_button = mainOverlay.AddWidget(EGE.GUI.WidgetType.WIDGET_BUTTON, "Menu_Button").SetSizePosition("10vw", "4vw", "calc(50% - 5vw)", "calc(50% + 2vw)").SetBackgroundColor([0,0,0,0], [0,0,0,0.5], [0,0,0,0.3]).SetBorder("All", "solid", 4, "Black", 50, "All").SetOnClicked(function(){window.location.href = "Game/Creator";});
- menu_button.AddWidget(EGE.GUI.WidgetType.WIDGET_TEXT, "Menu_Text").SetSizePosition("100%", "100%", 0, 0).AddText("Creator").TextAlign("Centered", "Centered");
- creator_OverallLoading.Step();
First we add a step in the loading system (for step 2). And now we create our widgets that we going to store in our global variables (Remember addWidget@ will always send back the created widgets).
For all widgets created will call all required setters, we also create a sub widgets text for the button.
And finally add another step to the loading system.
Note: almost all widgets setters are returning themselves to you can call a function on the same line like above.
Now the second part:
- //Launching
- EGE.Launch();
- creator_OverallLoading.Step();
- }
This is an important part, here we Launch the EGE and add one more step to the loading system, because if you set it properly the loading system will automatically close himself.
Created with the Personal Edition of HelpNDoc: Easily create HTML Help documents