Thursday, April 17, 2025
spot_img

Orientation change stretches sprite briefly earlier than scene hundreds in Cocos Creator 3.8.2 – Cocos Creator


Hello everybody,

I’m working with Cocos Creator 3.8.2, and I’m implementing orientation modifications dynamically on Android when switching scenes.

Right here’s the related code:

director.loadScene(this.ReturnGameSceneName(), () => {
    if (sys.platform === sys.Platform.ANDROID) {
        native.reflection.callStaticMethod(
            "com.cocos.recreation.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 aspect:

Exercise exercise = GlobalObject.getActivity();
if (exercise == null) {
    Log.e("setOrientation", "Exercise is null!");
    return;
}
Log.d(TAG, "ChangeOrientation: " + setorientaion);

CocosHelper.runOnGameThread(new Runnable() {
    @Override
    public void run() {
        if (setorientaion) {
            exercise.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            exercise.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }
});

Concern:

In some scenes, when switching orientation, the sprite briefly stretches for a cut up second (as if the orientation modifications simply earlier than the scene is absolutely loaded). It seems just like the orientation change is occurring too early, slightly than in sync with the scene transition.

Any steering or finest practices for dealing with this cleanly in Cocos Creator 3.8.2 can be appreciated!

Thanks prematurely!
@Tom_k

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles