Home Game Development Code Snippet: How to Enable Both Fit Width and Fit Height and Still Use Widget Component – Cocos Creator

Code Snippet: How to Enable Both Fit Width and Fit Height and Still Use Widget Component – Cocos Creator

0
Code Snippet: How to Enable Both Fit Width and Fit Height and Still Use Widget Component – Cocos Creator

[ad_1]

Hi,
@StudioAMK has an in depth tutorial on this, you may test it out right here:

Unfortunately, the code doesn’t work in Cocos Creator 3.6.1, so right here is the up to date code:

makeResponsive() {
    let deviceResolution = view.getViewportRect();
    let deviceRatio = deviceResolution.width / deviceResolution.top;

    let canvasResolution = view.getDesignResolutionSize();
    let canvasRatio = canvasResolution.width / canvasResolution.top;

    if (deviceRatio > canvasRatio) {
        view.setResolutionPolicy(ResolutionPolicy.FIXED_HEIGHT);
    } else {
        view.setResolutionPolicy(ResolutionPolicy.FIXED_WIDTH);
    }
}

*You must learn the unique tutorial (linked above) if you happen to don’t perceive the aim of this code snippet.

1 Like

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here