What is the use of setDesignResolutionSize in cocos studio?

1.1k Views Asked by At

In my appDelegate class i have code something like this,

while using cocos studio

auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::createWithRect("HelloCpp", Rect(0, 0, 960, 640));
        director->setOpenGLView(glview);
    }
    director->getOpenGLView()->setDesignResolutionSize(960, 640, ResolutionPolicy::SHOW_ALL);

Where as in a normal cocos2dx project

with out cocos studio

the code in appDelegate class is like this.

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

My doubt is, is it mandatory to setDesignResolutionSize, and also should it be the same for every device size???

1

There are 1 best solutions below

0
On

in cocos2dx all coordinates are based on design resolutions size. By doing so you can use the same coordinate system on all screen sizes. resolution policy SHOWALL displays the entire area without any change however, since not all devices are in same size, you will have black boarders depending on the screen size.

NO_BORDER policy will crop some of the surface but you will loose some part of the world depending on the device screen size. If you planning to do this then you have to make sure that important parts are in the safe zone so that your game is not effected. There is one thing you have to pay attention if you are using NO_BORDER policy. The design resolution will not be same as the visible area. If this is what you decided to go for a policy choice then you need visibleSize() and visibleOrigin() functions to help you out the location of sprites and game objects.

Perhaps the best method is to use FIXED_HEIGHT or FIXED_WIDTH policies. If you choose FIXED_HEIGHT policy then you simply telling the cocos2dx that you want to display the entire height with in the visible area of any device. The width can be cut off depending on the device. The width size of the Design resolution size will be recalculated. you can take this approach if you don't care about the width of the game. in other words, if your game requires the entire height for the game area FIXED_HEIGHT is your policy.

As you may have guessed FIXED_WIDTH policy works similar but for the width rather then the height.

Both FIXED_WIDTH and FIXED_HEIGHT modifies design resolution's width or height depending on what you choose. good thing about this is that the produced design resolution will be identical to the visible area. This makes it easier for you to locate, position your sprites on your game.

Some more info on these topics can be found on following links. with much clear explanations. although they are abit old, they give you an idea on how it all works. http://www.cocos2d-x.org/wiki/Multi_resolution_support

http://cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation