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() {

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?


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

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

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