I'm using C# and trying to get hardware mouse position. First thing I tryed was simple XNA functionality that is simple to use
Vector2 position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
After that i do the drawing of mouse as well, and comparing to windows hardware mouse, this new mouse with xna provided coordinates is "slacking off". By that i mean, that it is behind by few frames. For example if game is runing at 600 fps, of curse it will be responsive, but at 60 fps software mouse delay is no longer acceptable. Therefore I tried using what I thought was a hardware mouse,
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(out POINT lpPoint);
but the result was exactly the same. I also tried geting Windows form cursor, and that was a dead end as well - worked, but with the same delay. Messing around with xna functionality:
GraphicsDeviceManager.SynchronizeWithVerticalRetrace = true/false
Game.IsFixedTimeStep = true/fale
did change the delay time for somewhat obvious reasons, but the bottom line is that regardless it still was behind default Windows mouse. I'v seen in some games, that they provide option for hardware acelerated mouse, and in others(I think) it is already by default. Can anyone give some lead on how to achieve that.
Mouse.GetState()
is broken. Are you sure that you're getting the mouse position in the same frame as you're drawing it? Also remember that the Windows cursor has acceleration/deceleration enabled, so it feels more responsive. If you want to get closer to the hardware, you should hit DirectInput, which will give you movement deltas instead of absolute mouse positions. But I believeMouse.GetState()
is still the correct way to do it in XNA. \$\endgroup\$Mouse.GetState()
is not broken, and as long asIsFixedTimeStep == true
people should not be able to see delay unless compared directly with visible windows mouse. However setting IsFixedTimeStep to false at lower framerate it becomes visible to everyone. About direct input I considered that a posability(last resort). \$\endgroup\$