3
Vote

Game Width and Height

description

How do I change the resolution of my game ?
 
I have tried setting the width/height from the hosting usercontrol.
 
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        GameCanvas.Width = 1024;
        GameCanvas.Height = 768;
    }
 
I have tried changing the Graphics device manager from the Game's constructor
        _graphics = new GraphicsDeviceManager(this);
        _graphics.SynchronizeWithVerticalRetrace = false;
        _graphics.PreferredBackBufferWidth = 1024;
        _graphics.PreferredBackBufferHeight = 768;
 
I have tried Wiring the ClientSizeChanged event
        Window.ClientSizeChanged += WindowClientSizeChanged;
 
pivate void WindowClientSizeChanged(object sender, EventArgs e) {
        if (Window.ClientBounds.Width > 0 && Window.ClientBounds.Height > 0) {
            _graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
            _graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
        }
 
thanks

comments

SimpleNick wrote Apr 27, 2011 at 12:03 AM

I set up an event within the hosting user control like so.
public GameView() {
        InitializeComponent();
        LayoutUpdated += GameView_LayoutUpdated;
    }


    void GameView_LayoutUpdated(object sender, EventArgs e) {
        Game.Graphics.PreferredBackBufferWidth = (int)ActualWidth;
        Game.Graphics.PreferredBackBufferHeight = (int)ActualHeight;
        Game.Graphics.ApplyChanges();
    }
}

I receive a null exception from line 101 within GraphicsDevice.cs

set
        {
            GetCurrentRenderTarget()._viewport = value;
        }


[Arg_NullReferenceException]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.60401.00&File=mscorlib.dll&Key=Arg_NullReferenceException

What am I doing wrong ?

AName wrote Jun 28, 2011 at 7:35 PM

If you're in full screen, put these in your GameView constructor, immediately after you initialize _graphics:

_graphics.PreferredBackBufferWidth = 1024;
_graphics.PreferredBackBufferHeight = 768;

It works for me in full screen, and I didn't use this line at all:

_graphics.SynchronizeWithVerticalRetrace = false;

Otherwise, my guess is that you want to set the size of the Canvas that is holding your XNA game and/or the actual UserControl's size (make sure it's Width and not x.DesignWidth or w/e).

wrote Jul 5, 2011 at 4:38 PM

wrote Jan 2, 2012 at 3:20 AM

wrote Feb 14, 2013 at 6:13 PM