XNA Creators Club Online
Page 1 of 1 (11 items)
Sort Posts: Previous Next

Mouse is off sync

Last post 3/30/2009 11:16 AM by NinZip. 10 replies.
  • 3/18/2009 9:14 PM

    Mouse is off sync

    Hey this might be a bug I don't know.

    I have drawn my own mouse cursor in the game and have set the coordinates to equal the position of the mouse upon each update loop.
                MouseState m_Mouse = Mouse.GetState(); 
                m_MouseX = m_Mouse.X; 
                m_MouseY = m_Mouse.Y; 


    I then draw it at the end of the draw loop.
                mSpriteBatch.Draw(m_MouseCursor, new Rectangle(m_Mouse.X, m_Mouse.Y, 20, 30), Color.White); 
     


    The problem is when I played the game in windowed mode the cursor doesn't match exactly to the current position of my mouse. This has led to being able to click on items outside of the game even though the cursor suggests it's still in the game.
    When I play the game in full screen mode sometimes I can't pull the mouse cursor to the bottom of the screen, there seems to be a border which stops me.
    Is this a resolution issue? Or have I done the mouse code wrong?
  • 3/18/2009 11:10 PM In reply to

    Re: Mouse is off sync

    It's not a bug in XNA but something is wrong in your code.

    Why don't you turn on the windows cursor, to compare against.

    this

     

    .IsMouseVisible = true;

     

     

     

     

     

  • 3/18/2009 11:33 PM In reply to

    Re: Mouse is off sync

    gorky:

    It's not a bug in XNA but something is wrong in your code.

    Why don't you turn on the windows cursor, to compare against.

    this

     

    .IsMouseVisible = true;



    I miswrote that a bit, I didn't mean to suggest theres a bug in XNA.
    I've made the mouseVisible but when the game starts the cursor never seems to map exactly to the mouse pointer, it always seems to be at a distance.
  • 3/18/2009 11:38 PM In reply to

    Re: Mouse is off sync

    Could it be issues related to the window border at the top?
    I'm too busy writing computer graphics for my day job to have any games in play-test or peer-review.
    Twitter: twitter/guysherman
    Blog: www.guysherman.com
  • 3/19/2009 12:24 AM In reply to

    Re: Mouse is off sync

    How far off is it?

    Is it consistantly the same distance off?
  • 3/19/2009 12:43 AM In reply to

    Re: Mouse is off sync

    gorky:
    How far off is it?

    Is it consistantly the same distance off?


    It's about the same distance everytime. Also depends on where the mouse is when the program starts, sometimes the displacement is down right or sometimes its top right.
  • 3/19/2009 1:24 AM In reply to

    Re: Mouse is off sync

    I probably won't be able to answer again for awhile, (going back to work)

    but how far off is it on startup.  Before moving the mouse?

    Does the distance grow while the mouse moves?

    If you move the mouse outside your game during play, then do something with another application and move the mouse around, then go back to your game.  What are the results?  Same offset, or did the offset change.
  • 3/19/2009 10:00 AM In reply to

    Re: Mouse is off sync

    gorky:
    I probably won't be able to answer again for awhile, (going back to work)

    but how far off is it on startup.  Before moving the mouse?

    Does the distance grow while the mouse moves?

    If you move the mouse outside your game during play, then do something with another application and move the mouse around, then go back to your game.  What are the results?  Same offset, or did the offset change.


    The distance doesn't grow as you move the mouse around, it remains constant. The offset is different depending on where the mouse cursor is on start up, if you go do something in another application though the offset remains the same, so it must be something when the game starts up.

  • 3/20/2009 3:48 AM In reply to

    Re: Mouse is off sync

    If I were you, I would make sure to set the mouse at the screens center at application startup.

     

    Mouse.SetPosition(centerx, centery);
  • 3/20/2009 8:16 AM In reply to

    Re: Mouse is off sync

    NinZip,

    You might want to post a bit more code as I don't think anyone is going to be able to help you as it stands. I've written a game that runs completely in Windowed mode and draws the mouse cursor on screen so it is possible.
  • 3/30/2009 11:16 AM In reply to

    Re: Mouse is off sync

    Hey,
    Sorry this is so late, been busy for the past week.

    I tried centring the mouse at the start however there still seems to be a displacement. I added some break points and at the initialisation stage mouseX = 400 and mouseY = 300

    Upon the first update without any movement MouseX = 527 and MouseY = 239

     Here is all the mouse code I have in terms of movement.

    Initialising the variables.

            MouseState m_Mouse = Mouse.GetState();  
            MouseState m_LastMouseState = Mouse.GetState(); 
     
            int m_MouseX; 
            int m_MouseY; 
            int m_MouseMode; 
      
     
    Initialise()
            protected override void Initialize() 
            { 
                m_CharacterID = 0; 
                m_ItemID = 0; 
                m_LocationID = 0; 
                MouseState m_Mouse = Mouse.GetState(); 
     
     
                m_CentreX = this.Window.ClientBounds.Width / 2; 
                m_CentreY = this.Window.ClientBounds.Height / 2; 
     
                Mouse.SetPosition(m_CentreX, m_CentreY); 
                m_MouseX = m_CentreX; 
                m_MouseY = m_CentreY;  
     
     
     

    Then here is the code at the update stage:
            protected override void Update(GameTime gameTime) 
            { 
                m_Keys = Keyboard.GetState(); 
     
     
     
     
                MouseState m_Mouse = Mouse.GetState(); 
                m_MouseX = m_Mouse.X; 
                m_MouseY = m_Mouse.Y; 
     

    And at the drawing stage:
            protected override void Draw(GameTime gameTime) 
            { 
                GraphicsDevice.Clear(Color.CornflowerBlue); 
     
                mSpriteBatch.Begin(); 
     
     
                MouseState m_Mouse = Mouse.GetState(); 
                m_MouseX = m_Mouse.X; 
                m_MouseY = m_Mouse.Y; 


                mSpriteBatch.Draw(m_MouseCursor, new Rectangle(m_MouseX, m_MouseY, 20, 30), Color.White); 
     

Page 1 of 1 (11 items) Previous Next