Android orientation change not updating width and height

Android orientation change not updating width and height
0.0 0


Tried this on several devices, none seem to work in android. It functions correctly on iOS

Changed my androidManifest.xml to have

(instead of the default landscape)

The game starts in the correct orientation, and everything looks fine. However, when i rotate the device, the bottom left moves to the new bottom left, as expected, but the device seems to think that the values in Director::getInstance()->getWinSize(); are the same as they were before i rotated, and then goes off the screen and leaves a big black gap.

Anyone have any idea what’s going on and why it’s not updating to the new width/height?

I’m on 3.0beta1.


I’ve tried overriding cocos2d::Application::getInstance()->applicationScreenSizeChanged(newWidth, newHeight); so it does a callback and trying to manually set _winSizeInPoints in CCDirector to no good effect, or trying to call Director setVieport after that with those width and height values but then I end up with either a width or height of twice the scalefactor and the other at half the scalefactor.


People of the future: my solution was in my overridden applicationScreenSizeChanged function

run this code:

    auto director = Director::getInstance();
    auto eglView = EGLView::getInstance();
    eglView->setViewPortInPoints(0,0,newWi, newHeight);
    eglView->setFrameSize(newWidth, newHeight);

And in CCDirector.cpp add

else if (openGLView) {
            _winSizeInPoints = openGLView->getDesignResolutionSize();

after the if statement there


As a person in the future, I thank you for these posts. I’m trying to do something similar; when the device changes, I want to call a function in my Layer subclass that repositions all its children. Perhaps a stupid question: Could you walk me through the process you used to override applicationScreenSizeChanged? What is the most efficient way to wire that up to my Layer subclass so that the reposition function is called when needed? Thanks for any direction you can give me.


Thank you very much. It worked very well, except for the current scene, because the sprites have already positions established and they are not updated. So I make use of an custom event, triggered by the applicationScreenSizeChanged function, to update the location of the sprites, and almost everything worked fine (I still have some minor problems with textfields).