Jump to content
  • Advertisement
Sign in to follow this  
Upshaw

XNA | UI on WIndows Games?

This topic is 2589 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'm in the process of creating a strategy game, which is a change from my previous project I made that required no interactive UI or mouse input (Keyboard only), so the whole concept of creating a UI with XNA is a mystery to me.

Since my Strategy game is a tile-based, two-dimensional game, my click detection is mostly done with dividing te mouse position by the tile size, and returning that tiles' occupying Actor (The actual Tanks, Jets, Submarines, etc. of the game), which works well. My issue with laying a UI over the game is how would I do click detection for the buttons on the UI without getting it confused with clicks meant to be on the gameboard?

I thought about creating a seperate viewport below the main games' viewport, in much the same way the taskbar is below the desktop in windows. However, I'm not sure on the procedures for working wit multiple viewports, and if there are any restrictions between namespaces / scope / any roadblocks I may run into when attempting to alter one viewports' content based on another (Click a button on the UI viewport, cause action on the game viewport)

So, if someone could un-confuse me about this subject, that'd be fantastic. I wasn't sure whether to place this in this forum (XNA and DirectX) or in Beginners' questions. If it needs to be moved, feel free to do so.

Share this post


Link to post
Share on other sites
Advertisement
There's no reason for a separate viewport. It would do nothing to solve your problem. You still have 1 screen full of pixels.
Check if the mouse is colliding with UI buttons before you check if the mouse is colliding with the game. If it is, don't even check against the game.

Share this post


Link to post
Share on other sites
This is why I shouldn't do programming this early in the morning >_>

Well, in terms of creating the UI classes, is there any in-built XNA functionality that could help with this?

Share this post


Link to post
Share on other sites

This is why I shouldn't do programming this early in the morning >_>

Well, in terms of creating the UI classes, is there any in-built XNA functionality that could help with this?



Do you need more than SpriteBatch, DrawString, and/or RenderToTexture?

Make a kind of manager that will contain 1 whole GUI, and then a list of Button objects that have a position, a texture, and whatever other information you need them to have. Then you manager just loops over the list of buttons and checks for cursor collision.

It gets more complicated if you need the GUi to do complex things, but there are articles and premade libraries for that.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!