I am currently trying to get app rotations working on a cocos2d-x app. I have got it working normally except for one thing. I have ran into a bug where if I press the home button on iOS, rotate the screen, then re-enter the app, the current scene I am looking at will be shrunk on one axis and stretched on another. However, the objects on the screen are touchable at the correct location, not where they appear to be. Upon re-entering
didRotateFromInterfaceOrientation in the RootViewController will be called. This calls this method:
void UIHelper::setScreenForOrientation(bool landscape)
{
auto director = cocos2d::Director::getInstance();
auto glview = director->getOpenGLView();
auto frameSize = glview->getFrameSize();
Size s;
if (landscape) {
s = Size(std::max(frameSize.width, frameSize.height),
std::min(frameSize.width, frameSize.height));
} else {
s = Size(std::min(frameSize.width, frameSize.height),
std::max(frameSize.width, frameSize.height));
}
cocos2d::GL::invalidateStateCache();
cocos2d::GLProgramCache::getInstance()->reloadDefaultGLPrograms();
cocos2d::DrawPrimitives::init();
cocos2d::EventCustom recreatedEvent(EVENT_RENDERER_RECREATED);
director->getEventDispatcher()->dispatchEvent(&recreatedEvent);
director->setGLDefaultValues();
glview->setFrameSize(s.width, s.height);
glview->setDesignResolutionSize(glview->getDesignResolutionSize().width, glview-
>getDesignResolutionSize().height, ResolutionPolicy::FIXED_HEIGHT);
director->drawScene();
cocos2d::EventCustom orientationChangeEvent(ORIENTATION_CHANGE_EVENT);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&orientationChangeEvent);
}
Here is what it should look like:
,Here is what it looks like after leaving the app, changing orientation, and re-entering:
,