XNA and Mouse Position

Started by
1 comment, last by theycallhimSeeD 17 years ago
So I am having an issue that my XNA game does not detect the mouse position correctly. Here is my update function.

protected override void Update(GameTime gameTime)
        {                  
            
            MouseState m = Mouse.GetState();
            if (m.LeftButton == ButtonState.Pressed)
            {
                Console.WriteLine(m.X + " " + m.Y);
            }   

            base.Update(gameTime);
  }
Now the mouse coordinates should be relative to the upper left hand corner of the window. When I click there the output is nowhere near 0,0. Each run the numbers change. Examples: 84 -5 217 169 195 142 Any ideas?
Advertisement
Being that your code will have it spit out all the coordinates the entire time you're holding the button, I'm inclined to think that these are just some extreme values from clicking and possibly dragging a little before releasing. My personal advice would be to not worry about it until you're making something that uses it.

Try making a game where you click on little boxes or something and they change color. If that doesn't work (assuming the rest of the code is good), then we'll know you have a problem with the mouse position.
Hey I found the error. In attempting to make my game class a singleton class I screwed up some of the code. So the real reason of failure was that messed up singleton model. Once I fixed that the mouse issue went away. Thanks for the help.

This topic is closed to new replies.

Advertisement