Question

I'm currently working on a Win 8 Windows Store game (Monogame, C#). I set the graphics.PrefferedBackBuffers to 1366x768. The laptop that I use mostly to develop doesn't support this resolution neither does the external monitor connected to it, however everything gets scaled nicely so the sprites are compressed or stretched on different monitors (this doesn't hold if the game is dragged to another monitor while running). I need to use the mouse to drag game objects around but I notice that the mouse cursor works in the monitor resolution, so doing something like :

 if(objectSprite.BoundingBox.Contains((int)mouseCursos.x, (int)mouseCursos.Y))
 {
        objectSprite.isHooked = true;
 }

doesn't work since the mouse's coordinates are always different from the coordinates of the game objects. How do I get the current monitor's max resolution so I'll be able to scale the coordinates.

Please note that GraphicsAdapter.DefaultAdapter.CurrentDisplayMode returns 800x600.

Was it helpful?

Solution

Since Metro app's are generally full-screen by default (although they could be snapped too) you can use the following properties from the Window class:

Window.ClientBounds.Width
Window.ClientBounds.Height

Hope that helps.

OTHER TIPS

In my MonoGame Windows Store app ClientBounds somehow doesn't exist, Window.Current somehow is null, so I use this approach:

            CoreApplicationView v = Windows.ApplicationModel.Core.CoreApplication.MainView;
        var bounds = v.CoreWindow.Bounds;
        double w = bounds.Width;
        double h = bounds.Height;
        switch (DisplayProperties.ResolutionScale)
        {
            case ResolutionScale.Scale140Percent:
                w = Math.Round(w * 1.4);
                h = Math.Round(h * 1.4);
                break;
            case ResolutionScale.Scale180Percent:
                w = Math.Round(w * 1.8);
                h = Math.Round(h * 1.8);
                break;
        }
        ScreenSize resolution = new ScreenSize(w, h);
        if (ApplicationView.Value == ApplicationViewState.FullScreenLandscape)
            resolution = new ScreenSize(w, h);
        else if (ApplicationView.Value == ApplicationViewState.FullScreenPortrait)
        {
            resolution = new ScreenSize(h, w);
        }
        else if (ApplicationView.Value == ApplicationViewState.Filled)
        {
            resolution = new ScreenSize(w + 320.0 + 22.0, h); //snapped mode grip
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top