Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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.