Detect android orientation change?

Detect android orientation change?
0.0 0



I seem to be having trouble detecting the change when android rotates from portrait/landscape. Is there a proper way to detect this? I’d have expected this to change -


or this -


But neither change?



I’m no Sherlock Holmes but this thread is the first result that came up when searching for “android orientation change”:

Specifically, you need to implement this method in your AppDelegate:

virtual void applicationScreenSizeChanged(int newWidth, int newHeight);


You’re right - this method really does work. I’d looked at this before and dismissed it. The reason, I think, is because even if you do all that, this -


still reports the pre-rotate figure. I reckon that’s probably a bug in cocos unless there’s a really good reason for it not adjusting with the screen…?


I’m not sure why you’re assuming that’s a bug, Cocos2d-x just doesn’t update the OpenGL view’s size to match the device’s resolution on rotation changes. That seems like an uncommon use case, most games lock to an orientation (portrait or landscape), so there’s no need to ever handle that situation. For people who need that functionality, and it seems like you do, update the OpenGL view size like in the applicationScreenSizeChanged() method of the example thread.


Well, I still think this should change to reflect the change -

Director::getInstance()->getVisibleSize().width / height

At least after this -

glview->setDesignResolutionSize(newWidth, newHeight, resolutionPolicy);