How to update winSize, visibleSize, visibleOrigin of Director?

I noticed that Director::getWinSize(), Director::getVisibleSize() and Director::getVisibleOrigin() return the same value across device rotation.

I checked the CCDirector source files but there seems to be no straight forward way to achieve what I am looking for.

What is the suggested way to update these values? (So that they reflect the proper values in case of both portrait and landscape orientations)

Override applicationScreenSizeChanged in AppDelegate (only for ios and android):

void AppDelegate::applicationScreenSizeChanged(int newWidth, int newHeight)
{
	auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	if (glview)
	{
		auto size = glview->getFrameSize();
		if (size.equals(Size(newWidth, newHeight)))
			return;

		glview->setFrameSize(newWidth, newHeight);

		ResolutionPolicy resolutionPolicy = glview->getResolutionPolicy();
		if (resolutionPolicy == ResolutionPolicy::UNKNOWN)
			resolutionPolicy = ResolutionPolicy::SHOW_ALL;
		glview->setDesignResolutionSize(newWidth, newHeight, resolutionPolicy);
	}
}
3 Likes

Thanks! Its working perfectly.

BTW, I think I’ll have to re-render the Scene upon rotation (using the updated winSize, visibleSize, visibleOrigin). I am using Director::replaceScene(Scene*) for now, but it causes an ugly animation. I am thinking of creating a member function in the Scene class where the nodes will be updated via some ScaleTo, MoveTo actions.

Is this the right way?

Please mark my answer as solution.

Can you show animation?

How would you readjust the Scene after rotation?

You should support portrait and landscape design.