Jump to content

  • Log In with Google      Sign In   
  • Create Account


Mouse/pointer behavior with objects on screen


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 IndyOfComo   Members   -  Reputation: 522

Like
0Likes
Like

Posted 30 August 2013 - 07:34 AM

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?

 

Thanks!

 

 

 

*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.

Here is my technical background info.

Sponsor:

#2 Dave Hunt   Crossbones+   -  Reputation: 2335

Like
1Likes
Like

Posted 30 August 2013 - 08:00 AM

What you are looking for is "picking". There are two samples on the XNA site:

 

Picking

Picking with Triangle Accuracy






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS