Window Size - desktop dev

Topics: Platform UI
Aug 1, 2013 at 2:47 PM
Hello, I'm new here so it might be a newbie question but I have searched the forums and googled the problem with no results.
I am trying to setup the client window size at the begining of the initialization. But it always stays the same, if I set the Game.Window.AllowUserResize = true, i can manipulate client size manually, but how to set the initial state from code?
Coordinator
Aug 1, 2013 at 8:04 PM
In Game Constructor:
        graphics = new GraphicsDeviceManager(this);
        graphics.PreferredBackBufferHeight = 1024;
        graphics.PreferredBackBufferWidth = 768;

In AppDelegate:
            CCDrawManager.SetDesignResolutionSize(768f, 1024f, CCResolutionPolicy.ExactFit);
that should get you the size you want. it does not support dynamic resizing.
Aug 26, 2013 at 6:34 PM
Did you get this working? I am having the exaxt same problem and the solution posted is not working. I can change the resolution and it changes the size of the view inside the window (my sprites get bigger or smaller depending on the resolution) but the window size stays the same.

Please help. I am using the WindowsGL template, all I did was add a sprite and position it in the middle of the window. Now I just want to make the window size bigger.
Aug 26, 2013 at 7:08 PM
Edited Aug 26, 2013 at 7:11 PM
The solution I came up with does not satisfy me but it works. I made basic abstract class called BaseLayer with constructor initializing the BackBuffer sizes. And from now on every layer I create (Intro, Menu, GameLevel, Credits, Outro and so on...) inherits from BaseLayer.
public abstract class BaseLayer : CCLayerColor
    {
        protected BaseLayer()
        {
            DinoGame.Graphics.PreferredBackBufferHeight = Constants.RESOLUTION_HEIGHT;
            DinoGame.Graphics.PreferredBackBufferWidth = Constants.RESOLUTION_WIDTH;
            DinoGame.Graphics.ApplyChanges();
        }
    }
Oh, and the DinoGame object is the main type for your game (the class that you start with).
Aug 26, 2013 at 9:45 PM
Excellent. Thanks for the reply. I will try this.
Aug 26, 2013 at 10:19 PM
Edited Aug 26, 2013 at 10:29 PM
I found a solution. In my Program.cs file, I changed the size in there.
static class Program
{
    static void Main(string[] args())
    {
        using (Game1 game = new Game1())
        {
            game.graphics,PreferredBackBufferWidth = 1680;
            game.graphics.PreferredBackBufferHeight = 1050;
            game.Run();
        }
    }
}
Can we get some input from a cocos developer as to why this problem exists? Why does the cocos template have the code in the wrong place? You can delete the PreferredBackBufferWidth/Height in AppDelegate.cs and in Game1.cs and it doesnt break anything. Why is the code in there? And why is it repeated in those two files? And why is it there if it doesnt do anything?

I am really curious to know. I am afraid to invest much more time into cocos because there is no documentation, and then it appears the templates provided have errors.
Coordinator
Aug 27, 2013 at 1:30 AM
hey guys, see my original post at the top for information about when to set the back buffer. You should do it in the game constructor. Preferably you do it just before the device is being created. In XNA there is a callback from the graphics device that sets the preferred device settings.

You can see this in CCApplication.cs:
        if (service is GraphicsDeviceManager)
        {
            ((GraphicsDeviceManager)service).PreparingDeviceSettings += GraphicsPreparingDeviceSettings;
        }
When this callback is invoked, the device is created with your preferred background settings, which you set in the graphics device as I detailed at the top of this thread.

In CCApplication.cs, there is a preparing device settings callback:
    protected virtual void GraphicsPreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
    {
        e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
        e.GraphicsDeviceInformation.PresentationParameters.DepthStencilFormat = DepthFormat.Depth24Stencil8;
        e.GraphicsDeviceInformation.PresentationParameters.BackBufferFormat = SurfaceFormat.Color;
    }
In XNA, the presentation parameters are used to set the windows attributes. What you don't override in presentation parameters is thusly set by your graphics device settings.

Why this appears in two places in the template, I don't know. It's a bug. If you could log your bugs or other oddities that you find, that would help us. You can log your bugs here on codeplex or on github: https://github.com/Cocos2DXNA/cocos2d-xna
Coordinator
Aug 27, 2013 at 6:36 AM
Correction, since we are handling the device creation in CCApplication, you need to do this:
    protected override void GraphicsPreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
    {
        base.GraphicsPreparingDeviceSettings(sender, e);
        e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = 1024;
        e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = 768;
    }

Add that to your AppDelegate class and behold, your window size will change.
Coordinator
Aug 27, 2013 at 7:53 AM
On github: https://github.com/Cocos2DXNA/cocos2d-xna/pull/318

I've put up a fix for window resizing problems. When this merges you should be able to set the preferred back buffer as I described earlier (at the top of this thread) and it will apply properly. Snap will also work with this PR.