Search code examples
windowsvisual-studiococos2d-xcocos2d-x-3.0

cocos2d-x 3.x on Windows: How do I change the size of my game window?


When developing using cocos2d-x 3.x for a device, it automatically sets the GL view to fit the device. In VS2012 on windows, it creates a seemingly-arbitrarily sized window. How do I set the size of that window?


Solution

  • My solution was as follows.

    In AppDelegate.cpp:

    bool AppDelegate::applicationDidFinishLaunching() {
        auto director = Director::getInstance();
        auto glview = director->getOpenGLView();
        if(!glview) { 
            glview = GLView::create("My Game");
            glview->setFrameSize(800, 600);     // or whatever
            director->setOpenGLView(glview);
        }
        ...
    }
    

    In my particular use case, I'm setting the window sizes to various resolutions and aspect ratios to test my layouts. I'm sharing Q&A format because I couldn't find a straight answer to this anywhere.