Question

J'ai essayé de modifier l'orientation d'un appareil dans le projet HelloWorld Android.Mais j'ai un petit problème.J'ai suivi le guide hors 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);
 }
}

Alors, mon problème :en orientation Portrait, j'ai une bonne vue : belle vue, mais, en orientation paysage, j'ai ça :mauvaise vue.Ce que je fais mal?

Était-ce utile?

La solution

Rien de mal à cela, vous ne pouvez certainement pas utiliser les mêmes coordonnées lorsque vous changez d'orientation.Dans votre code, vous devez les traiter séparément, par exemple :

if (orientationIsLandScape()) {
     background->setPosition();
} else {
     background->setPosition();
}

le orientationIsLandScape()devrait être une fonction écrite par vous-même pour détecter l'orientation actuelle

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top