Skip to main content
GameDev.net gamedev.net
🔒 Locked

XNA and Mouse Position

Started by theycallhimSeeD Mar 29, 2007 at 1:17 AM 1 replies 1k views
Original Post
theycallhimSeeD
theycallhimSeeD
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?
NickGravelyn
NickGravelyn
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.
theycallhimSeeD
theycallhimSeeD
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.