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();
},