Answers for "Responsive layouts cocos creator"

1

Responsive layouts cocos creator

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();
},
Posted by: Guest on October-12-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language