SFML community forums
Help => General => Topic started by: newn on August 24, 2010, 09:48:18 am
-
Hi everyone. I thought of a way with lots IF statements. Is there any... smarter way to create a menu? Exit, options, that kind of stuff.
-
Well...I do it like this for each button:
if(MouseOver(Button))
{
Button.SetImage(Img_Mouseover);//a Image that for example lightens
if(Clicked(Button))
{
GameState = Next_GameState;
break;
}
}
else
Button.SetImage(Img);//The normal button-image
-
Thanks, that sounds nice for a mouse. I wasn't thinking about mouse, to tell the truth. But yea, i'll implement this feature too.
What i was thinking, is buttons, but as i accidentally wrote in another thread, while talking to a few people (multitasking sucks sometimes), seems, like i got it the right way, if use the menu with keyboard keys.
-
If you look at this tuto on the wiki (http://www.sfml-dev.org/wiki/en/tutoriels/multiecransjeu_en), I did use a simple menu with up and down keys.
-
I gave some source and a tutorial on the french wiki here : http://www.sfml-dev.org/wiki/fr/sources/abstract_menu
I'll work on a translation later, but you can try to use the code as it is presented.
In some word, you got 4 abstract class (and 3 utility ones) to create a menu structure that can respond to actions (up down left right use) and call for events. The Panel contains Widget that are parsed by a Cursor. The Widgets can call for WidgetEvents.
With this short technics, you can create menu like the one in the exemple screenshot. It don't respond to mouse click, but you can implement this though.