Sign in to follow this  
Upshaw

XNA | UI on WIndows Games?

Recommended Posts

Upshaw    100
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
Daaark    3553
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
Upshaw    100
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
Daaark    3553
[quote name='Brian.Upshaw' timestamp='1305909779' post='4813527']
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?
[/quote]


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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this