Implementing menu states
We will now move on to creating a simple menu state with visuals and mouse handling. We will use two new screenshots for our buttons, which are available with the source code downloads:
The following screenshot shows the exit feature:
These are essentially sprite sheets with the three states of our button. Let's create a new class for these buttons, which we will call MenuButton
. Go ahead and create MenuButton.h
and MenuButton.cpp
. We will start with the header file:
class MenuButton : public SDLGameObject { public: MenuButton(const LoaderParams* pParams); virtual void draw(); virtual void update(); virtual void clean(); };
By now this should look very familiar and it should feel straightforward to create new types. We will also define our button states as an enumerated type so that our code becomes more readable; put this in the header file under private
:
enum button_state { MOUSE_OUT = 0, MOUSE_OVER = 1, CLICKED = 2 };
Open up the MenuButton.cpp
file...