Setting up a GUI (Please Read Before Flaming)
Setting up a GUI (Please Read Before Flaming)
First Off, i'd like to introduce myself, i've posted here once as a guest, and i LOVE this engine so far. So to everyone, hello. Now onto my question.
Ok, i started writting a game and i started by using the "collision" example. How do i create a GUI that will start before the collision part does. Please don't just say "read the user interface tutorial" i read that, and it shows how to create a GUI, but it doesnt show you how to setup the GUI and then lead into your game.
While i'm on this subject (and to keep me from posting again), how do you set an image as a background for the GUI window (so you dont use the default one)
Thanks For Any Help
Obs
Ok, i started writting a game and i started by using the "collision" example. How do i create a GUI that will start before the collision part does. Please don't just say "read the user interface tutorial" i read that, and it shows how to create a GUI, but it doesnt show you how to setup the GUI and then lead into your game.
While i'm on this subject (and to keep me from posting again), how do you set an image as a background for the GUI window (so you dont use the default one)
Thanks For Any Help
Obs
Legality is a horrible barometer for morality.
I'm not sure if this is exactly what you want, but this is the way I tackled that particular problem.
I have an int called gameState. Each state means a different thing, for example:
1 = Main Menu
2 = Play Game
3 = Pause Menu
4 = etc, etc, etc...
My main loop is setup like this:
Simply use buttons or whatever to change the gamestate variable to access different areas.
If you need to use GUI elements in the main part of your game, make seperate GUI environments for, say.. the main menu, the pause menu, gui elements used during the game etc...
Hope this helps...
I have an int called gameState. Each state means a different thing, for example:
1 = Main Menu
2 = Play Game
3 = Pause Menu
4 = etc, etc, etc...
My main loop is setup like this:
Code: Select all
while(device->run() && driver)
if (device->isWindowActive())
{
switch(gameState)
{
case 1:
driver->beginScene(true, true, SColor(0,150,150,150));
guienv->drawAll();
driver->endScene();
break;
case 2:
driver->beginScene(true, true, SColor(0,0,128,128));
smgr->drawAll();
driver->endScene();
break;
};
}
If you need to use GUI elements in the main part of your game, make seperate GUI environments for, say.. the main menu, the pause menu, gui elements used during the game etc...
Hope this helps...
Maybe it's me. Maybe i'm just stupid (which is probably the case). When i run demo... it starts with a very short loading screen, and then it does a camera fly around thing... and then it drops me into a quake level. No GUI. I can see wher e the code is, and i can almost grasp the general idea. But if i cant see a code that actually works it doesnt end up helping me too much.
Legality is a horrible barometer for morality.
Perhaps it helps if i show you what i've done. This is not efficient or elegant code, it just works for
me and is very similar to iam13013's code (except there are only two gamestates).
I have a Client.cpp, where initializations take place and the while loop is:
MenuHandler and GameHandler are derived from IEventReceiver (Tutorial 4). They get a handle to the ingame
variable. If the player clicks on the "Join Game" Button in the main menu, "ingame" is set to true and the
gameHandler is the new event receiver (All GUI Elements are made invisible). If the player presses ESC while
in a game, "ingame" is set to false and the player is in the main menu again (before, all temporary game data is erased:
level meshes, player mesh, etc.).
But i guess that's not an elegant/efficient/nice way to do it! If you have enough time, looking at
IrrWizard or ICE is probably the better idea...
I hope it helps nonetheless.
andreas
me and is very similar to iam13013's code (except there are only two gamestates).
I have a Client.cpp, where initializations take place and the while loop is:
Code: Select all
...
int main(int argc, char *argv[]) {
...
bool ingame = false;
...
IrrlichtDevice *device = createDevice(EDT_OPENGL, ...);
MenuHandler menuHandler(device, &ingame);
GameHandler gamehandler(device, &ingame);
device->setEventReceiver(&menuHandler);
...
while(device->run()) {
device->getVideoDriver()->beginScene(true, true, SColor(0,10,10,30));
// If the player is in a game:
if (ingame) {
// this shouldn't be necessary every frame...
device->setEventReceiver(&gameHandler);
// update the game state
gamehandler.updateGameState();
}
// If the player is in the main menu:
else {
device->setEventReceiver(&menuHandler);
// draw the gui elements
menuHandler.updateMenuState();
}
device->getVideoDriver()->endScene();
}
...
MenuHandler and GameHandler are derived from IEventReceiver (Tutorial 4). They get a handle to the ingame
variable. If the player clicks on the "Join Game" Button in the main menu, "ingame" is set to true and the
gameHandler is the new event receiver (All GUI Elements are made invisible). If the player presses ESC while
in a game, "ingame" is set to false and the player is in the main menu again (before, all temporary game data is erased:
level meshes, player mesh, etc.).
But i guess that's not an elegant/efficient/nice way to do it! If you have enough time, looking at
IrrWizard or ICE is probably the better idea...
I hope it helps nonetheless.
andreas
-
- Posts: 277
- Joined: Thu Dec 15, 2005 6:11 pm
All of the Irrlicht scenenodes can get deleted with one function call(I can't remember what it is.) Why don't you have three functions, one for initialization, one for menu, one for game. In Init function, you set up the Irrlicht engine, create the window, stuff like that. Then you run the menu function, which at the beginning, attaches the scene nodes for the GUI stuff, then goes into the rendering loop where you detect what the user is selecting on the menu. If the user selects "Play" on the menu, you call the function PlayGame(), where you delete all the nodes and load all the scenenodes for the game. When you are done with the game, you delete the nodes again and reload the menu nodes, at which point you return to the menu. If you want, you can keep the nodes in memory, and just attach them when you need them. You can also detach the nodes as needed instead of calling the deleteall function, but it might be easier that way.