Jump to content
  • Advertisement
Sign in to follow this  
AgentShiva

linking GUI to game logic question

This topic is 3254 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

Hello everyone, I'm working on a GUI using the XNA framework and C#. I have come to somewhat of a roadblock though. I need to be able to link the UI components (buttons, checkboxes, etc) to game logic and I am not entirely sure how. At the moment I am using XML files to load in the UI components, which then get stored in lists in a GUI manager. I want/need to be able to set a the relationship between the UI component and the logic during the 'load' process of the UI. Any help is greatly appreciated :)

Share this post


Link to post
Share on other sites
Advertisement
Hey Shiva!

I do not use C#, but I can tell you it's really nothing if you take a systematic approach. You have a GUI, and apparently it is functional. Whenever you change a GUI element, you can say the element is at a different state.

So, what should your game logic know in order to "use" the GUI? What the states of each element are. Know where your data is, and ask yourself the classic question: How do I get this data from point A to point B?

But, I'm blabbing. The solution?: Type some 'Get' methods. It really does not get any simpler. [smile]

Hope this helps.
Cheers!
-Zyro

Share this post


Link to post
Share on other sites
Haha...I got so caught up in reflection that I thought it was the solution. I was trying to hook a method to say, a button, when I created the button (through reflection) and it works when the target is within the GUIManager (ie. another UIComponent) but outside of the GUIManager it gets a little more interesting.

However, I think I could use both methods hand in hand (seems kinda pointless to tell the main Game that one UIComponent needs to talk to another).

I'll draft up some quick get methods for everything else...man such a simple answer for a problem bugging me for so long. Guess I need to get back to the basics a bit huh.

Thanks for the reply Zyro.

Share this post


Link to post
Share on other sites
You're on the right path with reflection. Use C# events to alert your components about UI changes and vice versa.

A get method is great for a polling mechanism but as most developers will tell you, polling is bad. It is better to respond upon event activation rather than checking over and over if that event has fired.

Happy coding.

Share this post


Link to post
Share on other sites
Still a little shady on event based programming, but I will read up on it. I don't entirely understand how I would hook the events from the GUIManager to the main game, but I guess that's the fun part to figure out =D.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!