I am making a little tile based game, nothing big and complicated or
anything. But I want to start making a basic menu system for it and I
have never really done it before. What would the general code structure
be for a menu system?
So far I have made a menu class whos goal is to keep track of buttons
and other objects on the menu and draw the whole menu onto a surface
which can be fetched from one of its methods… it works like this…
// we add all the elements to the menu
// this gets passed the on screen location, size in tiles of the menu
and background color. Then it draws the menu onto a surface held in the
// would be used to move the menu around the screen
// gets passed your display or other surface you want to render it to to
finally draw it somewhere.
this is the actual class declaration to give you a general idea
int build (unsigned short tx, unsigned short ty, unsigned char r,
unsigned char g, unsigned char b, unsigned char a,SDL_Surface*
int draw (SDL_Surface* screen);
int move (int x, int y);
int addbutton (unsigned short xrel, unsigned short yrel, unsigned short
w, unsigned short h, SDL_Rect surface_rect, SDL_Surface*
buttonsurface); //returns the button number
int removebutton (int num);
int addtext (unsigned short xrel, unsigned short yrel, const char*
int removetext ();
int checkcollisions (); // this is only a stub so far but it would
return mabe a pointer to the element or button or something that it
collided on? or perhaps just a number… i dnno.
SDL_Surface* getsurface ();
private: SDL_Surface* surface; button buttons[MAXBUTTONELEMENTS]; xy loc; };
So my question is… is this generally how you go about making a menu
system? Any sugguestions about how I should approach it? How would
something like dragging work? (like picking up an item out of one menu
and putting it in annother).
elements I want to add would be buttons, dragable items, and a text
window with a text entry at the bottom.
Matt Pruett <@Matt_Pruett>