The main menu state
The main menu of any game out there is a major vein in terms of application flow, even though it's mostly overlooked. It's time we took a stab at building one, albeit a very simplistic version, starting as always with the header file:
class State_MainMenu : public BaseState{ public: ... void MouseClick(EventDetails* l_details); private: sf::Text m_text; sf::Vector2f m_buttonSize; sf::Vector2f m_buttonPos; unsigned int m_buttonPadding; sf::RectangleShape m_rects[3]; sf::Text m_labels[3]; };
The unique method to this class is the MouseClick
. Since we're dealing with a menu here, predictably enough it will be used to process mouse input. For private data members, we have a text variable for the title, size, position and padding size variables for buttons, drawable rectangles for buttons and text variables for button labels. Let's throw it all together:
void State_MainMenu::OnCreate(){ m_font.loadFromFile("arial.ttf"); m_text.setFont(m_font...