I tried change a device orientation in HelloWorld Android project. But, i have a small problem. I followed guide from off.site:
1. Add nativeInit(w, h); to cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxRenderer.java -> void onSurfaceChanged(GL10 gl, int w, int h).
2. Add this code to void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h):
cocos2d::CCEGLView* view = cocos2d::CCDirector::sharedDirector()->getOpenGLView();
if (!view) {
...
} else {
...
if (view->getFrameSize().width != w || view->getFrameSize().height != h) {
view->setFrameSize(w, h);
view->setDesignResolutionSize(w, h, kResolutionShowAll);
}
}
So,my problem: in Portrait orientation i have a good view: nice view, but, in landscape orientation i have that:bad view. What i do wrong?
Nothing wrong with it, definitely you cannot using the same coordinates when you change your orientation. In you code, you should deal with them separately, for example:
if (orientationIsLandScape()) {
background->setPosition();
} else {
background->setPosition();
}
the orientationIsLandScape()
should be some function written by yourself to detect the current orientation