XNA Creators Club Online
Page 1 of 1 (10 items)
Sort Posts: Previous Next

Resize game window on startup

Last post 03/10/2007 19:03 by DavidWHart. 9 replies.
  • 03/10/2007 15:44

    Resize game window on startup

    I can't really figure out how to resize the game window. The game has a background that i need the window to fit. How do I change the window size according to the 2D texture I have as the games background? I have tried resizing forms but the game isn't called like a form I'm guessing. Can anyone help with my little problem. It's really bugging me. Without the clientbounds being set right, the players go off of the playing field/court.

    Thanks in Advance! :)

  • 03/10/2007 15:45 In reply to

    Re: Resize game window on startup

    Add these two lines into your Game's constructor with whatever values you need:

    graphics.PreferredBackBufferWidth = 1280;
    graphics.PreferredBackBufferHeight = 720;

    That will allow you to set the window size (or rather set the size of the backbuffer which will then dictate the necessary size of the window).
  • 03/10/2007 16:00 In reply to

    Re: Resize game window on startup

    oh i get it now. thx alot. So you mean i set the BufferWidth and Height to the Textures dimensions in pixels?
  • 03/10/2007 16:05 In reply to

    Re: Resize game window on startup

  • 03/10/2007 16:30 In reply to

    Re: Resize game window on startup

    where exactly is the games constructor. I may have put it in the wrong area because the size doesnt change at all. I've tried putting in the Draw Method and tried at the Game Initialization.
  • 03/10/2007 16:35 In reply to

    Re: Resize game window on startup

    Well constructor is the method that's named same as your class..You can write ctor and press tab to recreate it..
    Simply put those lines in construct..Definatly not in Draw()!
    __________________________________________________________________
    Stefan Virag | XNA Framework Developer
  • 03/10/2007 16:57 In reply to

    Re: Resize game window on startup

    tried that it doesnt seem to work though:

     protected override void Initialize()
    {
    // TODO: Add your initialization logic here
    graphics.PreferredBackBufferHeight = 272;
    graphics.PreferredBackBufferWidth = 480;
    base.Initialize();
    base.Window.Title = "Shakam Pong";
    }
  • 03/10/2007 17:10 In reply to

    Re: Resize game window on startup

    Answer
    Reply Quote
    I just tried, it seems you DO need to write that in constructor ONLY..won't work in initialize()..

    public Game1()
    {
    graphics = new GraphicsDeviceManager(this);
    content = new ContentManager(Services);
    graphics.PreferredBackBufferHeight = 800;
    graphics.PreferredBackBufferWidth = 1000;
    }

    __________________________________________________________________
    Stefan Virag | XNA Framework Developer
  • 03/10/2007 17:48 In reply to

    Re: Resize game window on startup

    ahhh. Finally problem fixed. Can't believe it took about 2 hours to get the answer lol.

    Thanx, Stefan

  • 03/10/2007 19:03 In reply to

    Re: Resize game window on startup

    By the way, I found this nice trick which you might be interested in knowing. I had problems when I first played with XNA because I couldn't find anywhere a list of available display modes to itterate through. All I wanted to do was to set my fullscreen application to the highest or current available resolution.

    Well I finally found out a few months ago that ONLY when the GraphicsDevice has been initialized by the GraphicsDeviceManager, you can go grab it's DisplayMode property which stores that exact resolution, or the system's current display mode.

    Constructor:
    public MyGame()
    {
    this.graphics = new GraphicsDeviceManager(this);
    this.graphics.PreferMultiSampling = true;

    this.content = new ContentManager(Services);
    }


    Initialize:
    protected override void Initialize()
    {
    DisplayMode displayMode = this.graphics.GraphicsDevice.DisplayMode;

    this.graphics.PreferredBackBufferWidth = displayMode.Width;
    this.graphics.PreferredBackBufferHeight = displayMode.Height;
    this.graphics.IsFullScreen = true;
    this.graphics.ApplyChanges();

    base.Initialize();
    }

Page 1 of 1 (10 items) Previous Next