I found a solution, but it is not great as you have to modify the lib. Anyway
1.Go to cocos2dx/platform/android/java/src/org/cocos2dx/lib
2.In Cocos2dxRenderer.java add the following to the onSurfaceChanged method
@Override
public void onSurfaceChanged(final GL10 pGL10, final int pWidth, final int pHeight) {
nativeInit(pWidth, pHeight);
}
3.Go to your project folder and in proj.android/jni/[prjcpp]/main.cpp modify the Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit method
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
if (!CCDirector::sharedDirector()->getOpenGLView())
{
//...
}
else
{
//...
CCEGLView *view = CCEGLView::sharedOpenGLView();
if (view->getFrameSize().width != w || view->getFrameSize().height != h) {
view->setFrameSize(w, h);
view->setDesignResolutionSize(w, h, kResolutionShowAll);
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_ORIENTATION_CHANGED, NULL);
}
}
}
4.Before you can subscribe to the EVENT_ORIENTATION_CHANGED you must declare it in CCEventType.h:
#define EVENT_ORIENTATION_CHANGED "event_orientation_changed"
5.You can subscribe to the event:
CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(Scene::orientationChangedCallback), EVENT_ORIENTATION_CHANGED, NULL);
You can avoid using the event by checking the orientation in the update method of any CCScene or CCLayer object. I did it by comparing the width and height of the screen:
bool Scene::isLandscape()
{
CCSize _screenSize = CCDirector::sharedDirector()->getWinSize();
if (_screenSize.width > _screenSize.height)
return true;
return false;
}
There has to be a better solution! Please share!