SFML community forums

Help => General => Topic started by: GrislyGames on April 07, 2013, 09:20:25 pm

Title: main menu
Post by: GrislyGames on April 07, 2013, 09:20:25 pm
So I've been trying to figure out how to make a main menu in SFML 2.0 c++. I'm new at programming with it (only been using it for about a month now) and I'm now trying to make a game which is very important to have a main menu in. I'm not sure whether I should just use bool variables or whether I should be doing something else ( I've tried with the bool variables and wasn't able to get it to work). Thank you for your time! :D
Title: Re: main menu
Post by: eXpl0it3r on April 08, 2013, 10:05:15 am
If you're new to programming with C++ in general, I really suggest to get a good book (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) an read it through. C++ is not a language you learn within a month or two.

A main menu can be implemented and many, many different ways. One popular is to use different states/screens. There are numerous tutorials on the internet, about game states etc, just google a bit. There's also one on the SFML wiki (https://github.com/SFML/SFML/wiki/Tutorial%3A-Basic-Game-Engine) and I've created a SmallGameEngine (https://github.com/eXpl0it3r/SmallGameEngine) based on a tutorial for SDL (http://gamedevgeek.com/tutorials/managing-game-states-in-c/), but I used SFML.

In theory, a main menu can just be an image with a few buttons; you capture the mouse and/or keyboard input and give some visual feedback when the mouse is over a button or a button is selected.
Title: Re: main menu
Post by: bumblecorn on April 09, 2013, 05:03:32 pm
A couple of nested if-statements for each button should do the trick. Super-pseudo-mode activate:

if (button contains mouse)
{
     Switch to highlighted state of the button

     if (mouse button is pressed)
     {
           do things
     }
}