Responsive Layout - tried to port to V3 - but need help

So I tried to port the code from this post to CC v3:

This is the code from the post:

makeResponsive() {
    let canvas = this.node.getComponent(cc.Canvas);
    let deviceResolution = cc.view.getFrameSize();
    
    // calculte design ratio
    let desiredRatio = canvas.designResolution.width / canvas.designResolution.height;
    // calculte device ratio
    let deviceRatio = deviceResolution.width / deviceResolution.height;

    if (deviceRatio >= desiredRatio) {
        canvas.fitHeight = true;
        canvas.fitWidth = false;
    } else if (deviceRatio < desiredRatio) {
        canvas.fitHeight = false;
        canvas.fitWidth = true;
    }
},

onLoad() {
    this.makeResponsive();
},

which all went fine, but I can’t find an equivalent in the new API to this part :

canvas.fitHeight = true;
canvas.fitWidth = false;

It’s not on canvas, not on view and it seems it’s also nowhere else.
Is this deprecated? Is there another way? Did I miss something?

Thanks.

It’s in the project setting now, you can refer to this

https://docs.cocos.com/creator/3.0/manual/en/editor/project/#general

Thanks.
So this can’t be set dynamically anymore via code?

(as you can see in the code there is an if statement that changes the fit height/width depending on the device ratio…)

You can, but you need to set with view API

https://docs.cocos.com/creator/3.0/api/en/classes/core.view-2.html#setdesignresolutionsize

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.