creating a menu

Started by
8 comments, last by smhouston 19 years ago
i'm new to directx (ok,i've had around 7 months experience),but i've only done the basics of directx for example rendering images,camera movement,lighting,directinput i'm creating a game but when it starts up i want a menu to appear,with a few buttons on like "Start Game" and "Sound On/Off".however,i don't know how to do it.i was reading the creating a simple GUI tutorial,but it seems way to complicated for what i'm trying to do can anyone give me any advice?any help appreciated
Advertisement
in simple terms, you'll have to create a loop which scans for user input. anyway that's how I do it... :)
let's say you have 5 options, then if user presses right or left arrow , the focus needs to be changed to the next/previous option.
if user press [enter] the current 'choise' (focus) will be executed; exit the loop, destroy the whole intro screen, and jump to the routine that is connected with the chosen option. (like 'game start' will go to, heck, the starting of the game).
Quote:Original post by Marmin
in simple terms, you'll have to create a loop which scans for user input. anyway that's how I do it... :)
let's say you have 5 options, then if user presses right or left arrow , the focus needs to be changed to the next/previous option.
if user press [enter] the current 'choise' (focus) will be executed; exit the loop, destroy the whole intro screen, and jump to the routine that is connected with the chosen option. (like 'game start').

i see.say if i chose "start game",would i need to open another window for the game to load up in?or can it all be done in the same window i.e. remove the components of the window,then add the game components?
I use the same window;
after a player clicks on the selection,
I 'destroy' all the things that happen in the 'menu' screen (and are connected to my window), and immediately after that I 'create' the 'game start' screen (in the same window, with the same DirextX device).
Of course, this is all done OOP (object orientated), if you don't use classes , dynamic arrays, or objects, then things get a lot harder.
Quote:Original post by Marmin
I use the same window;
after a player clicks on the selection,
I 'destroy' all the things that happen in the 'menu' screen (and are connected to my window), and immediately after that I 'create' the 'game start' screen (in the same window, with the same DirextX device).
Of course, this is all done OOP (object orientated), if you don't use classes , dynamic arrays, or objects, then things get a lot harder.

i;m wanting to do it OOP aswell,just not much experience in doing so as only started studying about it for 7 months.i don't suppose you know any good examples i could use as a guide?
If you want to show a menu before starting the game (like a menu containing the game's settings), a simple alternative would be to use the "resourses" from your compiler. In VisualC++, for example, you can insert a dialog resourse to your project (by Insert/Resources...) and to personalize it with buttons, text boxes, selection boxes etc.
Take a look at the lessons from here to have an idea on how to make that.

On the other hand, you could also use sprites to create/simulate a menu with a better visual quality. Sprites are very easy to use and there are many information about them on the net. Here, for example.
Another similar way is to render images from textures using an ortho projection. Look at here. The MontadorSprites's interface was made using this resource. Note that I switch the texture of the buttons according to the mouse's input.
In my engine is one object (CDefaultWnd), with many global functions and one manager (CGamePos) class for store all objects (it has dynamic list of all added classes), that depends from this basic object (CDefaultWnd).

Then i create objects CGameMenu : public CDefaultWnd, CIntro : public CDefaultWnd, CIngame : public CDefaultWnd and add all of this to CGamePos manager. In this manager i can set one of this game classes as active :

CGameMenu* menu = new CGameMenu ();
CIntro* intro = new CIntro ();
CIngame* ingame = new CIngame ();

m_gamepos->AddClass (menu);
m_gamepos->AddClass (intro);
m_gamepos->AddClass (ingame);

m_gamepos->SetActiveClass (intro);

In parent OnDraw function is called CGamePos for run draw function of active class :

m_gamepos->DrawActiveClass ();

which takes active class (defined with function SetActiveClass) and runs his DoDraw function.

When i need to switch from Intro to menu, i only call m_gamepos->SetActiveClass (menu) and engine is automatically switch active class to menu class.

In SetActiveClass something is like this :

if (m_activeclass) m_activeclass->ReleaseData ();
if (m_newclass)
{
m_newclass->InitData ();
m_activeclass = m_newclass;
}


Messages (key pressing etc.) is created same way.
ah ha,thanks for your help! i've actually managed to build a very basic menu now.only problem now is how do you detect where the mouses position is say if i click the left button,how do i get those co-ordinates where the mouse has been clicked? */me hopes there's a simple command*
Quote:Original post by smhouston
ah ha,thanks for your help! i've actually managed to build a very basic menu now.only problem now is how do you detect where the mouses position is say if i click the left button,how do i get those co-ordinates where the mouse has been clicked? */me hopes there's a simple command*

Are you using C++? To get the mouse's position you could use:

If fullscreen mode:

POINT Cursor;
GetCursorPos( &Cursor );

If windowed mode, convert the cursor coordinates from the screen to client:

ScreenToClient( hWnd, &Cursor );
Quote:Original post by adriano_usp
Quote:Original post by smhouston
ah ha,thanks for your help! i've actually managed to build a very basic menu now.only problem now is how do you detect where the mouses position is say if i click the left button,how do i get those co-ordinates where the mouse has been clicked? */me hopes there's a simple command*

Are you using C++? To get the mouse's position you could use:

If fullscreen mode:

POINT Cursor;
GetCursorPos( &Cursor );

If windowed mode, convert the cursor coordinates from the screen to client:

ScreenToClient( hWnd, &Cursor );


ah right,thanks.i've tried to get my screen into full mdoe when starting up,but it doesn't work.the menu starts loading up then shuts down after 2 seconds

also,when i render a textbox through classes like DrawText(200,300 etc...),where the numbers indicate where to draw the text,is that the same as the mouses co-ordinates fore ample if i put the mouse cursoe directly over "200,300",would the mouse co-ordinates be the same or is that a different system?

This topic is closed to new replies.

Advertisement