So what I'm working on right now is the part where the pointer on the screen (currently controlled by mouse and/or keyboard, eventually by gamepad as well) needs to know what object it is 'over'. Obviously this is for the detecting of selecting UI buttons, units, stuff like that. But I'm also wanting to have 'hover over' text, so it's not all about detecting pointer placement when a button is clicked.
My partner had a bit of this functionality already coded and it works fine, problem being it was written just for one object(the cities.) Clearly we want to reduce code duplication and have this handled outside of the specific eligible elements. I looked through my two XNA books* but I didn't see anything addressing this topic. (If I missed it, feel free to simply point it out to me.)
First, isn't there already something out there which will handle this? A class or interface included in XNA or C#? I found VisualTreeHelper, but I'm not sure that's going to work, or at least we'll have to redo a lot of our work to fit into Visual objects. (Overall I wasn't given the impression VTH was what one wanted for games, sounded more officey.) Am I missing it?
Secondly, if we do need to write our own, what I was thinking was creating a class which held a 2D List--the inner list holds objects which have the boundaries of objects on the screen which should react to the pointer, and the outer list would be layers of those objects (so that a unit takes priority over the terrain it's standing on.) Does that sound decent, or problematic?
*my XNA books: XNA Game Studio Creator's Guide 2ed, Cawood & McGee
XNA 4.0 Game Development by Example: Beginner's Guide, Jaegers
Edited by IndyOfComo, 30 August 2013 - 07:35 AM.