Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

fisheyel83l

Game Menus - General Questions

This topic is 5914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was building a Menu class the other day, and I ran into some problems. I figured a "menu" had to have a background pic (or a string to hold an image filename), and an array of objects that the user can maniplate (buttons, etc.). I planned to create an array of these Menu objects to represents all the "menus" in my game, like the title screen and the options screen. My problem: I constructed an array of RECTs to represent clickable areas on the menu (like the buttons), and then passed this array to the menu object via a function call. My code didn''t compile, because I couldn''t find a way to dynamically assign one array to another. How can I allow an array of any size to be passed? My Menu class looks like this: class CMenu { public: void SetRects( RECT rectArray[5], int numRects ); //Don''t want to hard-code that "5" public: char* file; RECT clickableAreas[5]; // <-should be a pointer to a RECT? // Again, I don''t want to hard-code that "5" }; void CMenu::SetRects( RECT rectArray[5], int numRects ) { //What can go here? Right now, I copy element by element, but I''d rather just rearrange pointers so that clickable areas points to rectArray, regardless of its size. } As you can probably tell, I don''t have a firm grasp of pointers, but I know they''re the answer to my problem. Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
Hmm I think this might help.

void CMenu::SetRects ( RECT *lpzRc, int izNum )
{
for (int i = 0; i < izNum; i++ )
{
clickableAreas.left = lpzRc->left;
clickableAreas[i].top = lpzRc->top;
clickableAreas[i].right = lpzRc->right;
clickableAreas[i].bottom = lpzRc->bottom;
}
}

I hope that helped. Basicly you have a point to a RECT that way you can pass in any amount of RECTs. Even a array of them. Just be sure to watch out that you don''y go over the array limit. Using a point is better in a way because when you only going to use part of the object you passing, a point will only make a reference to that part and use. Rather then pssing the whole damn object or what ever on the stack. I think I got that right?! You might want to look for some pointer tutorials. Because pinter are cool and you can do lots of thangs with them.
I hope I helped some what. Good luck.

Share this post


Link to post
Share on other sites
Some mods...

void CMenu::SetRects ( RECT *lpzRc, int izNum )
{
delete[] clickableAreas; // Delete any old stuff
clickableAreas = new RECT[izNum];
memcpy(clickableAreas, lpzRc, sizeof(RECT)*izNum);
}


should work...

Johan Ersvik

Share this post


Link to post
Share on other sites

typedef vector RECTS;
RECTS m_rects;

CMenu::AddRect(RECT _rect) {
m_rects.push_back(_rect);
}

CMenu::DrawRects() {
RECTS::const_iterator end = m_rects.end();
for(RECTS::iterator cur = m_rects.begin();cur!=end;++cur) {
DrawRect(*cur);
}
}


about this.. stl is good for dynamic data amount.. i''ll suggest you give it at least a try.. (and here the documentation of everything..: http://www.sgi.com/tech/stl/table_of_contents.html)

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
Thanks for the suggestions, and thanks for the link, davepermen. One more question: Do I have to change any of my variable declarations? Right now both arrays are declared like this:
RECT variable[5];
What should they change to?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!