Window size and resolution control

How can I properly control the window size? I’ve tried
“graphics.PreferredBackBufferWidth = X;
graphics.PreferredBackBufferHeight = Y;”,
but the screen just gets all weird. The window appears to be square, actually, and no matter what I do, it just scales everything inside itself.

I’m using a 800x600 image as background, but the image inside the window is just all over the place.

That’s the right way. If you set the preferred back buffer size outside of your game constructor you need to call graphics.ApplyChanges for the changes to take effect.

What happens exactly? Nothing should scale automatically. Maybe share some code so we can see what you’re doing.

This is the code I’m using:

“graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
graphics.ApplyChanges();”

This is what I get on the PC:

And if I stretch the window, it gets like this:

Also, on the Windows Phone (same project and code), it gets even worse:

p.s.:The purple is that “default” color that every template draws, but I changed it from corn flower blue to purple.

How are you drawing that rectangle?

spriteBatch.Begin();
spriteBatch.Draw(titleScreen,new Rectangle(0, 0,this.Window.ClientBounds.Width,this.Window.ClientBounds.Height),Color.White);
spriteBatch.End();

I figured I’d be able to set the window size somewhere, or make it use the image size. Is that not the case on WS apps?

I tried this now:

spriteBatch.Draw(titleScreen, new Rectangle(0, 0, 800, 600), Color.White);

The window won’t resize the image now if I resize it, but it still won’t draw the rectangle correctly, making it way taller than it’s width.

Which MG version ? 3.6?

The recent develop brunch has a fix to force-update the scale of swapchain.
(that PR solves several issues with W&WP 8.1)

Two more pending PR that might be relevant:


(I just updated it to resolve a conflict but the build server takes some time…, click on the ‘Show All Checks’/Package Windows SDK/Artifacts to get it once it’s ready)

For the next one to have any effect you must update your .xaml and replace swapchainbackgroundpanel with swapchainPanel (same as the Windows 10 template)


http://teamcity.monogame.net/viewLog.html?buildId=39118&buildTypeId=MonoGame_PackagingWindows&tab=artifacts

Also note that MG on windows store apps wont resize the client window as the Desktop does.

1 Like

Yup!

Woud this fix it for me? I tried changing SwapChainBackroundPanel to SwapChainPanel manually here, but it stopped working (but that’s to be expected since I have no Idea what I’m doing :v )

Oh yeah, I remember something about it being kind of a “simulated” full screen or something, because W8 apps would go fullscreen by default. Still, I though it would maybe

That about the SwapChainBackroundPanel->SwapChainPanel is about the second PR.

But try the first one first (#5569). The issue you have sounds very similar to #5555.

How exactly do I go about to do that? I mean, where do I add that code? I noticed an address there (MonoGame.Framework/Graphics/GraphicsDevice.DirectX.cs), but I can’t seem to locate that in the project :frowning:

Ok, forget everything and let’s take it step by step from the start.

What exactly are you trying to achieve?
Platform, MG Version, etc?

Allright! I’m on Windows 10, using MonoGame 3.6 on VS2015 :v
My project is on that hybrid Windows 8.1/Windows Phone 8.1 template.

I’m actually just studying this template, since I like to build stuff on the Windows Phone but sometimes it’s just a pain to deploy everything to the device, so I figured it’d be fun to be able to deploy on the PC too without having to mess with file linking and emulators and all.

I was following a tutorial for the good old Windows template when I came across this issue which I described at the beginning. If I tell the code to draw the screen at 800x480, it works on the phone, so I’m not super worried about it, but no matter what I do, it just won’t draw the screen correctly on the Windows Store build. That’s what I’d like to achieve.

Alrighty then!

https://msdn.microsoft.com/en-us/library/bb203889(v=xnagamestudio.31).aspx

My suggestion is to adjust your GUI/Cameras to Viewport. Even windows mobile devices have different resolutions and aspect rations.
for example this line with scale to fill the viewport
var vp = GraphicsDevice.Viewport;
spriteBatch.Draw(titleScreen, new Rectangle(0, 0, vp.Width, vp.Height), Color.White);

Think of graphics.PreferredBackBufferWidth as input for ApplyChanges(), don’t use it to get the current backbuffer dimensions, although usually it will have the same value.

You can set the window to 800x480 if you like but use the desktop project for that.
AppStore apps dont resize the window, instead they scale the backbuffer.
(also you skip the ‘Deploy’ step while you debug)
use this code in your Game() constructor, or in Initialize().
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 600;
graphics.ApplyChanges();

1 Like

this is my code,different behavour for xbox and desktop

            if (App.IsXbox())
            {

                _graphics.PreferredBackBufferWidth = 1920;
                _graphics.PreferredBackBufferHeight = 1080;

                Debug.WriteLine("running on xbox");
                IsMouseVisible = false;
                _graphics.IsFullScreen = true;
            }
            else 
            {
                Debug.WriteLine("not running on xbox");

                IsMouseVisible = true;

                int w = (int)Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds.Width;
                int h = (int)Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds.Height;
                //int w = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
                //int h = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
                Debug.WriteLine($"SW:{w};SH:{h}");


                _graphics.PreferredBackBufferWidth = w;

                _graphics.PreferredBackBufferHeight = h;


            }