Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

If I use mouse coordinates to select a sprite does XNA provide a built in way to return the top-most sprite on the screen at a coordinate?

I am trying to highlight the selected sprite, but when iterating through my sprites at the specific mouse location there can be multiple sprites found. The way my game works any one of the sprites found is valid to be on top.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I don't believe XNA has a built in way to do this. You should definitely implement some kind of ordering or layering system so one sprite gains precedence over the others (unless your game needs multiple sprites to be selected at once from the same mouse click). Once a sprite processes the selection no other sprites should be given the chance to.

share|improve this answer
1  
I headed down this path and it will solve my issue. –  riv_rec Apr 5 '11 at 15:59
add comment

It sounds like you need to assign a "depth" or "Z" value to your sprites that defines which is "on top" of each other. Then you would iterate through the sprites as usual but the sprite returned would have the highest "Z" value.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.