سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

+1 to Tom. Also, I would just like to share my answer and experience to everyone.

Remember, do not set the screen size "AFTER" the director set the GL view. This causes some problem with bounds detection on some nodes most notably cocos2d::ui::Button and other ways on how create buttons. I am using cocos2d-x v3.6

Check my answer here: cocos2d::Menu click detection is a bit off to bottom left whenever using a custom window size

Doing this way will cause some problem:

auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
    glview = GLViewImpl::create("My Game");
    director->setOpenGLView(glview);
}

director->getOpenGLView()->setFrameSize(width , height);

Clicking the button, doesn't kick in the callback. Which is frustrating. Probably out of your frustration as well you click all through out the screen and notice there are some part of the screen (most likely bottom left part) which triggers the callback as if the bounding box of the node lies there. It doesn't even match the position and the size of the node in question. I can reproduce the problem whenever I change the screen size like the one I describe above. So never ever do it like that.

Tom's answer is the correct way of changing screen size.

I hope this will deter anyone doing it this way. I swear to God, this post could have save me heck of time solving this.

Cheers!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top