Skip to main content
GameDev.net gamedev.net
🔒 Locked

SFML - How to create a main menu?

Started by Meerul264 Jan 14, 2013 at 6:40 PM 3 replies 16k views
Original Post
Meerul264
Meerul264

My question is quite straight forward. How to I create a main menu?

I suspect it is coded in the event loop. I want to test making a main menu by clicking on a button of the main menu, to start another loop (like starting the game for an example).

Thanks

BeerNutts
BeerNutts

Well, there are multiple ways of doing it. The crude way would be to show a picture, and when in that menu mode, check for mouse clicks within certain X/Y locations for "button presses".

A more elegant way would be to create Button classes that give you notifications on being pressed and have the abililty to be drawn.

An even better method might be to use previously created UI methods developed for SFML. Check out the SFML Project forum at sfml-dev.org and look for different GUI's there.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
wicked357
wicked357

Depends on how you want to do it. You could always make it from scratch which is fairly simple or you can follow the tutorials for intergrating one of the GUI libraries into your project.

Meerul264
Meerul264

I want to make it from scratch, from just simply using the sf::Shapes class. I don't want to get fancy because this is my first time making main menu.

I'm thinking to use the sf::Event::MouseButton::x and sf::Event::MouseButton::y, passing them to a function from a class called MenuButton,

and then make an if statement with condition that checks if the mouse cursor is on the button's x and y locations.

I bet there's more easier way this this...

And sorry I already did some googling but couldn't find the material that I need.

EDIT:

Actually I can use getPosition() too...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.