game menu

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
endri
Posts: 1
Joined: Wed Jun 12, 2019 1:55 pm

game menu

Post by endri »

hello everyone
I am a beginner in irrlicht and I wanted your help to create a basic game menu in c++ with play, resume and quit buttons.
Thank you :)
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: game menu

Post by greenya »

You need to get a pointer to IGUIEnvironment, which can be done after device creation: env = device->getGUIEnvironment(). Add window, Add buttons with parent to be the window. To see stuff on screen, you need make sure GUI gets drawn: env->drawAll() should be called after you draw scene (if any) and before driver->endScene(). After these steps you will be able to see the menu, but it will do nothing interesting. To handle events you need to device->setEventReceiver() with you custom event receiver.

P.S.: i suggest you to read code of examples which comes with Irrlicht Engine; they show how to use IGUIEnvironment, e.g. create and handle the GUI in Irrlicht. There is a good example 05.UserInterface that shows good chunk of how it can be done.
chronologicaldot
Competition winner
Posts: 685
Joined: Mon Sep 10, 2012 8:51 am

Re: game menu

Post by chronologicaldot »

Something like this:

Code: Select all

 
int main() {
irr::IrrlichtDevice* device = irr::createDevice( irr::video::EDT_OPENGL, irr::core::dimension2du(1200,800));
if ( !device ) return 1;
 
irr::gui::IGUIEnvironment*  env = device->getGUIEnvironment();
 
irr::core::dimension2du buttonSize(200,60);
irr::core::vector2di buttonCorner(200, 200);
 
env->addButton("New Game", irr::core::recti(buttonCorner, buttonSize));
buttonCorner.Y += (irr::s32) buttonSize.Height + 5;
env->addButton("Quit", irr::core::recti(buttonCorner, buttonSize));
 
while( device->run() ) {
device->getVideoDriver()->beginScene();
env->drawAll();
device->getVideoDriver()->endScene();
}
 
device->drop();
 
return 0;
}
 
Post Reply