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.

I have 2 coordinates (X,Y). I have also a 10x10 array. By these coordinates I have to find the rectangle in which is my pointer at the moment. How could I handle it?

share|improve this question
    
This isn't stated clearly. Where did the pointer come into it? You already have two coordinates and you can calculate a rectangle from that. –  doppelgreener May 19 '12 at 8:38
1  
Since he mentioned a 10x10 array and the rectangle in which the pointer is in I guess he might be talking about having a tile grid on screen and figuring out which tile is under the mouse pointer. But yeah the question is very unclear, and we could use more information such as, where does the grid start. –  David Gouveia May 19 '12 at 8:52

1 Answer 1

If your grid array is displayed as a Rectangle(ox,oy, 10*CELL_SIZE, 10*CELL_SIZE), where (ox,oy) is an offset...

then the cell coords are

  xCell = (x-ox)/CELL_SIZE;
  yCell = (y-oy)/CELL_SIZE;

of course you should check the coords are in right range (0..9,0..9)

share|improve this answer

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.