Hi everyone,
I’m working with Cocos Creator 3.8.2, and I’m implementing orientation changes dynamically on Android when switching scenes.
Here’s the relevant code:
director.loadScene(this.ReturnGameSceneName(), () => {
if (sys.platform === sys.Platform.ANDROID) {
native.reflection.callStaticMethod(
"com.cocos.game.AppActivity",
"ChangeOrientation",
"(Z)V",
isLandscape
);
}
if (orientation === macro.ORIENTATION_LANDSCAPE) {
view.setDesignResolutionSize(1024, 576, ResolutionPolicy.FIXED_HEIGHT);
} else if (orientation === macro.ORIENTATION_PORTRAIT) {
view.setDesignResolutionSize(576, 1024, ResolutionPolicy.FIXED_WIDTH);
}
});
And on the Android side:
Activity activity = GlobalObject.getActivity();
if (activity == null) {
Log.e("setOrientation", "Activity is null!");
return;
}
Log.d(TAG, "ChangeOrientation: " + setorientaion);
CocosHelper.runOnGameThread(new Runnable() {
@Override
public void run() {
if (setorientaion) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
});
Issue:
In some scenes, when switching orientation, the sprite briefly stretches for a split second (as if the orientation changes just before the scene is fully loaded). It looks like the orientation change is happening too early, rather than in sync with the scene transition.
Any guidance or best practices for handling this cleanly in Cocos Creator 3.8.2 would be appreciated!
Thanks in advance!
@Tom_k