I’ve seen this done in Geometry Dash (which is also programmed with Cocos2d-x c++) and I want to know how to:
A) Scale every element according to the window size
B) Maintain aspect ratio when resizing window
C) Refresh size and position of each element when window size is altered
D) Allow switching to full screen in-game
I’m very new to cocos2dx and c++, so I figured I would stop here to try and figure this all out.
Thank you to anyone who helps!!
In AppDelegate.cpp, find the applicationDidFinishLaunching() function:
bool AppDelegate::applicationDidFinishLaunching() {
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::createWithRect("MyGame", cocos2d::Rect(0,0,960,640)); // Initial window size
director->setOpenGLView(glview);
}
// Set the Design Resolution Size
// This is the screen size you used to design your game.
// Example: You designed your game on a 960x640 screen
director->getOpenGLView()->setDesignResolutionSize(960, 640, ResolutionPolicy::SHOW_ALL);
// ... (other settings)
return true;
}
In the example above, I used ResolutionPolicy::SHOW_ALL. You can try other policies to see which one best suits your game.
Thanks, Patterson. That explanation helps clarify how the design resolution works. Just to confirm, if I want UI elements to reposition correctly when resizing the window, should I manually update their positions in the onResize event, or is there a built-in way to handle that?