Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SFML Blueprints

You're reading from   SFML Blueprints Sharpen your game development skills and improve your C++ and SFML knowledge with five exciting projects

Arrow left icon
Product type Paperback
Published in May 2015
Publisher Packt
ISBN-13 9781784398477
Length 298 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Adding a menu to the game

Now that we have all the pieces in place to build a basic menu, let's do it with our fresh GUI. We will build two of them. The main, game-opening one and the pause menu. This will show you the different usage possibilities of our actual GUI.

If you have understood what we have done until now well, you would have noticed that the base component of our GUI is Frame. All the other widgets will be displayed on the top of it. Here is a schema that summarizes the GUI tree hierarchy:

Adding a menu to the game

Each color represents a different type of component. The trunk is sf::RenderWindow and then we have a Frame attached to it with its Layout. And finally we have some different Widget. Now that the usage has been explained, let's create our main menu.

Building the main menu

To build the main menu, we will need to add an attribute to the Game class. Let's call it _mainMenu.

gui::Frame _mainMenu;

We then create an enum function with different possibilities of values in order to know...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime