Advertisement

Mouse pointer out of applicationresolution when running fullscreen

Started by July 30, 2015 11:58 PM
2 comments, last by Thomas Wiborg 9 years, 5 months ago

Im having some problems when running my application at fullscreen.

My game is currently running at 800x600 resolution. When im in windowed mode my mouse pos x and y is 0.0 upper left corner and 800.600 bottom right.
If im running my game in fullscreen its still 0.0 in upper left corner but at bottom right it changes to 1920x1080.
My mouse then follows the resolution of my screen and not the applications resolution.

Is there a way to fix this, maybe a workaround or something like that?

Here are my constructor for Game1.cs and Initialize


  public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            Window.IsBorderless = true;

            graphics.PreferredBackBufferWidth = screenWidth;
            graphics.PreferredBackBufferHeight = screenHeight;

            graphics.IsFullScreen = true;
        }


        protected override void Initialize()
        {
            Mouse.SetPosition(0, 0);

            IsMouseVisible = true;

            currentGameState = GameState.MainMenu;
            
            base.Initialize();
        }

//Thomas Wiborg

The following thread has some discussion about essentially the same problem, and some pointers on how to solve it:

http://www.gamedev.net/topic/670408-resolution-scaling-and-world-screen-coords/

Hello to all my stalkers.

Advertisement
Ill take a look.
Thank you Lactose!

//Thomas Wiborg

If people wonder how i managed it.... I made this method.
Now my mousePos is scaling after the resolution. Works great.


public Vector2 ReturnNewMousePosScale(float defaultComputerResolutionWidth, float defaultComputerResolutionHeight, float gameScreenWidth, float gameScreenHeight, Vector2 defaultMousePos)
        {
            Matrix ScaleMatrix = Matrix.CreateScale(defaultComputerResolutionWidth / gameScreenWidth, defaultComputerResolutionHeight / gameScreenHeight, 0.0F);

            Vector2 Scale = new Vector2(ScaleMatrix.M11, ScaleMatrix.M22);

            defaultMousePos = new Vector2(getMouseState.X, getMouseState.Y);

            return defaultMousePos = defaultMousePos / Scale;
        }

//Thomas Wiborg

This topic is closed to new replies.

Advertisement