XNA Width And Height Problem

Started by
8 comments, last by Spool 7 years, 11 months ago

So I have a problem now with my XNA stuff, I'm not sure what the computer is doing here :/ , first off, a game is in Full Screen,

and I have setted the resolution:


width = graphics.PreferredBackBufferWidth = 900;
height = graphics.PreferredBackBufferHeight = 1300;
graphics.IsFullScreen = true; 

I am now fighting with taking a screenshot and for some reason now that XNA is fullscreen taking a screenshot and pasteing it in paint doest work its all white idk why, so anyways I wanted to show you:

I made also some code to print mouse position


 public void DrawHelp()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Tab))
            {
                spriteBatch.DrawString(Font, string.Format("MouseX: {0}", cursorRect.X),
                new Vector2(10.0f, 35.0f), Color.Black, 0f, Vector2.Zero, 0.90f, SpriteEffects.None, 0f);
                spriteBatch.DrawString(Font, string.Format("MouseY: {0}", cursorRect.Y),
                new Vector2(10.0f, 50.0f), Color.Black, 0f, Vector2.Zero, 0.90f, SpriteEffects.None, 0f);
            }
        }

and well as noted above my width is (SHOULD BE) = 900, but in-game, it really isn't. The first thing that is telling me that it isn't is drawing my menu buttons which arent on the middle of a screen (button.X = (width/2 -(button.Width / 2))


// width of my buttons is 150 and the reason i did that is 
// becouse when setting the drawing coordinates it always uses the upper left corner of the texture

buttons are way too much to the left side, but their coordinates arent wrong, what is wrong is the window size that is different than what I setted it to be. But another thing that is telling me for sure that width is not 900 and height is not 1300 is that

becouse when I go wayyy to the left with my mouse, MouseX: 1279 and when I go at the bottom of the window with my cursor its

MouseY: 959.

How can that be so? And what is a solution for this problem? Thanks in advanced

Advertisement

Hi there!

To me it seems that your actual resolution stayed? 1280*960, at least based on the mouse positions in the bottom right corner (1279, 959).
I suspect you are trying to change the resolution once your game is already runing, since otherwise in the constructor of your Game class implementation, the code snippet you posted should work without any problems...

So the resolution not changing is most probably due to not actually applying the set changes to your graphics device. Try calling the ApplyChanges method of the GraphicsDevice, or of the GraphicsDeviceManager of the game (latter preferred!), like so:


graphics.PreferredBackBufferWidth = 900;
graphics.PreferredBackBufferHeight = 1300;
graphics.IsFullScreen = true;
graphics.ApplyChanges();

Br.

Blog | Overburdened | KREEP | Memorynth | @blindmessiah777 Magic Item Tech+30% Enhanced GameDev


public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            width = graphics.PreferredBackBufferWidth = 900;
            height = graphics.PreferredBackBufferHeight = 1300;
            graphics.IsFullScreen = true;
            graphics.ApplyChanges();
        }

This is Game1 constructor and yet when I move cursor to down-right corner MouseXY(1279, 959) stil...

I really have no idea what is wrong here I just can't think of a possbile solution for this and have no idea why my game doesn't have

that window size :/

You are setting the preferred width and height. I really doubt that 900x1300 is a supported fullscreen resolution by your video card. So the XNA code tries its best to give you a resolution that is close to what you are requesting

To further elaborate on nscu121978's answer.

"If you request a back-buffer resolution that is not supported by the output device, the XNA Framework automatically selects the highest resolution supported by the output device. For example, if a graphics back buffer with a resolution of 1920×1080 (1080p or 1080i) is created and displayed on a device with 480i resolution, the back buffer automatically is resized to 480i."

https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphicsdevicemanager.preferredbackbufferwidth.aspx

This is verbatim from the MSDN website on the use of preferredBackBufferWidth & Height.

Also, it seems there's a general consensus that the ApplyChanges Method should only be called within the update method of your game class, not entirely sure that it matters, but it's worth a shot.

Marcus Hansen

I have Nvidia msi gt 620 and http://www.geforce.com/hardware/desktop-gpus/geforce-gt-620/specifications it says that my max resolution

is 2048 x 1536 so idk why 900x1300 would be a problem.

I have Nvidia msi gt 620 and http://www.geforce.com/hardware/desktop-gpus/geforce-gt-620/specifications it says that my max resolution

is 2048 x 1536 so idk why 900x1300 would be a problem.

yes, your max resolution is 2048x1536, but that does not imply that anything less than that is acceptable. to get an idea of what all video modes your video card supports do the following (assuming Windows 10 but other versions of Windows should be similar):

1 - Right Click your desktop and choose "Display settings"

2 - Click "Advanced display settings" at the bottom of the new window

3 - Now in this window you will see a drop down box titled "Resolution"

4 - This drop down box contains all the resolutions supported by your video card

I am sure they is probably a quicker way to get this information but I dont hack around in Windows too much.

Is your monitor 1280x960? That would be explain the mouse coordinates.

As for the screenshots, are you using the keyboard shortcut for printscreen? If so, that doesn't work with XNA games in fullscreen, you'll have to use a program like fraps or add in code to save it in the game such as: http://xboxforums.create.msdn.com/forums/p/67895/594286.aspx

Thanks everyone ^_^

You could always set your preferred width and height to your monitors resolution. You could also set this up in a OnWindowSizedChanged method that is used when your window size is changed. You could check for full screen or non full screen and use graphics.PreferredBackBufferWidth = Window.ClientBounds.Width; You might have to check for the syntax on that. But I use something similar with my game. I set the minimum resolution of the window and then test against that size in OnWindowSizedChanged. Works well for me. Good Luck.

This topic is closed to new replies.

Advertisement