You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class AdaptAll extends cc.Component {
|
|
@property()
|
|
isByChange = true;
|
|
onLoad() {
|
|
if (this.isByChange) {
|
|
cc.view.setResizeCallback(() => this.resize())
|
|
}
|
|
this.resize();
|
|
}
|
|
|
|
public curDR: cc.Size;
|
|
public resize() {
|
|
var cvs = cc.find('Canvas').getComponent(cc.Canvas);
|
|
//保存原始设计分辨率,供屏幕大小变化时使用
|
|
// if (!this.curDR) {
|
|
this.curDR = cvs.designResolution;
|
|
// }
|
|
var dr = this.curDR;
|
|
var s = cc.view.getVisibleSizeInPixel();
|
|
var rw = s.width;
|
|
var rh = s.height;
|
|
var finalW = rw;
|
|
var finalH = rh;
|
|
// if ((rw / rh) < (dr.width / dr.height)) {
|
|
// //!#zh: 是否优先将设计分辨率高度撑满视图高度。 */
|
|
// //cvs.fitHeight = true;
|
|
|
|
// //如果更长,则用定高
|
|
// finalH = dr.height;
|
|
// finalW = finalH * rw / rh;
|
|
// }
|
|
// else {
|
|
// /*!#zh: 是否优先将设计分辨率宽度撑满视图宽度。 */
|
|
// //cvs.fitWidth = true;
|
|
// //如果更短,则用定宽
|
|
// finalW = dr.width;
|
|
// finalH = rh / rw * finalW;
|
|
// }
|
|
this.node.width = cvs.designResolution.width;
|
|
this.node.height = cvs.designResolution.height;
|
|
console.log("222222222",this.node.width,this.node.height)
|
|
cvs.node.emit('resize');
|
|
}
|
|
} |