动态修改场景的canvas属性设置,需要两套布局节点坐标信息
start() {
this.updateCanvasSize();
cc.view.setResizeCallback(() => {
this.updateCanvasSize();
})
},
// 自由切换横竖屏,动态设置设计分辨率和适配模式。
updateCanvasSize() {
let size = cc.view.getFrameSize();
if (size.width > size.height) {
this.canvas.fitWidth = false;
this.canvas.fitHeight = true;
this.canvas.designResolution = cc.size(1920, 1080);
this.showLandscape();
} else {
this.canvas.fitWidth = true;
this.canvas.fitHeight = false;
this.canvas.designResolution = cc.size(1080, 1920);
this.showPortait();
}
},