Main menu appear and disappear?
-
Gold_Fusion
- Posts: 26
- Joined: Tue Jan 20, 2004 9:25 pm
- Location: England
- Contact:
Main menu appear and disappear?
How would you make a menu appear and disappear when you press escape? I can get as far as setting a variable on when the escape key is pressed, but what I have no idea what to do next. Could I just hide the entire menu? Would that be the best way of doing it? Or should it be re-created and destroyed each time?
you can do it either way.
for an example, check out ICE: (get v1.0, its simplest)
http://www.skyesurfer.net/keless/IrrLicht/ICE/
for an example, check out ICE: (get v1.0, its simplest)
http://www.skyesurfer.net/keless/IrrLicht/ICE/
a screen cap is worth 0x100000 DWORDS
Maybe:
Make 2 Interface-States
1 for Game Menús where you can select a new game,the map and stuff, and the other for the game when you are playing.
in the loop when drawing you can put something like this:
if (Interface_State == GUIMENU)
DrawGUIMenuStuff();
else
DrawInGameStuff();
and in the eventreceiver with the input;
if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown)
if (event.KeyInput.Key == KEY_ESCAPE)
SwitchInterfaceState();
else
{
if (Interface_State == GUIMENU)
InGameKeyPressed(event.KeyInput.Key);
else
InGUIKeyPressed(event.KeyInput.Key);
}
I think ICE do this better .
Make 2 Interface-States
1 for Game Menús where you can select a new game,the map and stuff, and the other for the game when you are playing.
in the loop when drawing you can put something like this:
if (Interface_State == GUIMENU)
DrawGUIMenuStuff();
else
DrawInGameStuff();
and in the eventreceiver with the input;
if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown)
if (event.KeyInput.Key == KEY_ESCAPE)
SwitchInterfaceState();
else
{
if (Interface_State == GUIMENU)
InGameKeyPressed(event.KeyInput.Key);
else
InGUIKeyPressed(event.KeyInput.Key);
}
I think ICE do this better .
-
Gold_Fusion
- Posts: 26
- Joined: Tue Jan 20, 2004 9:25 pm
- Location: England
- Contact:
typically your game is updated every loop. simply have an if(!paused) before updating your game data.
for an example of this, see gs_Main in my IrrLicht Tetris game:
http://www.skyesurfer.net/keless/IrrLicht/tetris/
for an example of this, see gs_Main in my IrrLicht Tetris game:
http://www.skyesurfer.net/keless/IrrLicht/tetris/
a screen cap is worth 0x100000 DWORDS
-
Gold_Fusion
- Posts: 26
- Joined: Tue Jan 20, 2004 9:25 pm
- Location: England
- Contact:
A) not clearing the screen:
in m_driver->beginScene(true, true, irr::video::SColor(0,0,0,0)) the first parameter asks whether or not to clear the screen, simply pass it false instead of true.
I dont suggest doing this when using GUI elements however, as you will get bad results.
B) printf() calls will go to std out, which happens to be the console (the "dos window"), so yes. if you compile the project such that it does not show the console, the printf statements will have no visible effect.
in m_driver->beginScene(true, true, irr::video::SColor(0,0,0,0)) the first parameter asks whether or not to clear the screen, simply pass it false instead of true.
I dont suggest doing this when using GUI elements however, as you will get bad results.
B) printf() calls will go to std out, which happens to be the console (the "dos window"), so yes. if you compile the project such that it does not show the console, the printf statements will have no visible effect.
a screen cap is worth 0x100000 DWORDS
Re: Main menu appear and disappear?
i destroy and re-create the menus as needed.Gold_Fusion wrote:How would you make a menu appear and disappear when you press escape? I can get as far as setting a variable on when the escape key is pressed, but what I have no idea what to do next. Could I just hide the entire menu? Would that be the best way of doing it? Or should it be re-created and destroyed each time?
this is what i do when the user presses ESC to clear the menus
Code: Select all
void ClearGui() {
irr::gui:: IGUIElement* ele = grr.env->getRootGUIElement();
ele->removeChildren();
}
Code: Select all
void ShowMainMenu() {
irr::core::rect<irr::s32> buttonpos(SX(10),SY(200),SX(140),SY(240));
gameManager.SetButtonCallback(GB_PRACTICE,c_StartPracticeGame); grr.env->addButton(buttonpos, 0,GB_PRACTICE, L"Practice"); buttonpos.UpperLeftCorner.Y += SY(50); buttonpos.LowerRightCorner.Y += SY(50);
gameManager.SetButtonCallback(GB_MULTIPLAYER,c_ShowMultiPlayerMenu); grr.env->addButton(buttonpos, 0, GB_MULTIPLAYER, L"Multiplayer"); buttonpos.UpperLeftCorner.Y += SY(50); buttonpos.LowerRightCorner.Y += SY(50);
gameManager.SetButtonCallback(GB_OPTIONS,c_ShowOptionsMenu);grr.env->addButton(buttonpos, 0, GB_OPTIONS, L"Options"); buttonpos.UpperLeftCorner.Y += SY(50); buttonpos.LowerRightCorner.Y += SY(50);
gameManager.SetButtonCallback(GB_QUIT,c_QuitGame); grr.env->addButton(buttonpos, 0, GB_QUIT, L"Quit");
}
-
Gold_Fusion
- Posts: 26
- Joined: Tue Jan 20, 2004 9:25 pm
- Location: England
- Contact:
Thanks, I didn't know about removeChildren() or the GUI root.
A) Is there a way to group GUI elements so that I can destroy a particular menu and recreate it each time (the main menu) and have a different menu just appear and hide (the game menu)? The groups would let me remove all the Main Menu ones togethor, and hide all the Game Menu ones, I suppose.
B) Can I change the action of the minimise, maximise, and close buttons on a GUI window so that I can unpause the game as it's closed?
A) Is there a way to group GUI elements so that I can destroy a particular menu and recreate it each time (the main menu) and have a different menu just appear and hide (the game menu)? The groups would let me remove all the Main Menu ones togethor, and hide all the Game Menu ones, I suppose.
B) Can I change the action of the minimise, maximise, and close buttons on a GUI window so that I can unpause the game as it's closed?
a. Yes, use parentage and assign the menu items to the menu and all the menus to a main menu. Assign the main menu to the root node.
This will be a lot easier to generate sets of elements if you want to use the GUIHandler Class.
b. The buttons don't do anything on the IGUIWindow. So you can set them to do anything by getting the Element and setting up handling for it. The command for getting the element is in the IGUIWindow help section.
This will be a lot easier to generate sets of elements if you want to use the GUIHandler Class.
b. The buttons don't do anything on the IGUIWindow. So you can set them to do anything by getting the Element and setting up handling for it. The command for getting the element is in the IGUIWindow help section.
Crud, how do I do this again?
actually, there is no removeChildren() function, i coded it myself and added it to the irrlicht source in IGUIElement.hGold_Fusion wrote:Thanks, I didn't know about removeChildren() or the GUI root.
A) Is there a way to group GUI elements so that I can destroy a particular menu and recreate it each time (the main menu) and have a different menu just appear and hide (the game menu)? The groups would let me remove all the Main Menu ones togethor, and hide all the Game Menu ones, I suppose.
B) Can I change the action of the minimise, maximise, and close buttons on a GUI window so that I can unpause the game as it's closed?
Code: Select all
//! Removes All Children
virtual void removeChildren() {
// delete all children
core::list<IGUIElement*>::Iterator it = Children.begin();
while (it != Children.end()) {
(*it)->Parent = 0;
(*it)->drop();
it = Children.erase(it);
}
}