XNA Windows Resolution / Mouse Position Bug

Posted by Ian Hern on Game Development See other posts from Game Development or by Ian Hern
Published on 2014-05-31T11:45:47Z Indexed on 2014/05/31 16:06 UTC
Read the original article Hit count: 276

Filed under:
|
|
|

In XNA, when in windowed mode and resolution (set via PreferredBackBufferWidth/Height) is close to the resolution of the display, the view is distorted (zoomed in a bit)and the mouse coordinates are wrong.

Here is what it looks like when I draw a bunch of lines to the screen.

(Normal, Error on my ASUS Notebook G73Jh, Error on my EEE PC 1001P)

Normal Lines Laptop Lines Netbook Lines

In the top left of the screen the mouse position is correct, but the further you get away the more out of sync it becomes. Here are some images of the mouse in different positions and the game drawing a circle underneath where it thinks the mouse is.

(Top Left, Bottom Right)

TopLeftMouse BottomRightMouse

If you shrink the resolution by a couple pixels then it goes back to working like normal, my first though at a fix was to limit the max resolution to a little smaller than the display resolution. I figured out the maximum resolution that works in a couple different modes, but there doesn't seem to be a pattern that would allow me to determine it based off the display resolution.

Computer | Screen Resolution | Max Error-Free | Difference

ASUS Notebook G73Jh | 1920x1080 | 1924x1059 | +4x-21

ASUS Notebook G73Jh | 1024x600 | 1018x568 | -6x-32

EEE PC 1001P | 1024x600 | 1020x574 | -4x-26

Because the differences don't form a pattern I can't hack in a solution, the one even has +4 which baffles me.

Here is a project that demonstrates the problem, just set the resolution to the resolution of your display.

Any ideas on how I might fix this issue?

As an insteresting aside, I tried to use FRAPS to capture a video of the issue but fraps actually records without distortion or mouse offset.

© Game Development or respective owner

Related posts about XNA

Related posts about xna-4.0