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 a player in the center of the screen, where I also have my mouse position origin. (0,0) I would like to know the direction of the mouse, imagine splitting the screen with a X, so the top quadrant would be north, the bottom would be south... and so on. So if my mouse was at 5,-100 it should log ("North") as that is just a bit to the left and up 100 pixels.

share|improve this question
    
Come on people. This is a valid question, even though it's simple. Explain your down votes if you're going to down vote. –  Byte56 Dec 21 '12 at 19:39
    
Without the accepted answer it is difficult to understand exactly what is being asked. This question reads more like a statement. Since this site strives to be a knowledge base for future users consider rephrasing as a clearer question. –  Alex Shepard Dec 21 '12 at 19:46
    
-1 Severe lack of research –  Anko Dec 22 '12 at 2:25

1 Answer 1

up vote 10 down vote accepted
if (Abs(Y) > Abs(x)) {
  if (Y < 0) {
    return "North";
  } else {
    return "South";
  }
} else {
  if (X < 0) {
    return "West";
  } else {
    return "East";
  }
}
share|improve this answer
    
I thought for sure some trig would be needed, I guess not! –  FreshJays Dec 21 '12 at 13:59
2  
Might want a slight amendment to the code to handle the X == Y == 0 case. –  Trevor Powell Dec 21 '12 at 23:05

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.