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.
18 lines
467 B
18 lines
467 B
1 week ago
|
//宽度自适应
|
||
|
const { ccclass, property, disallowMultiple, menu } = cc._decorator;
|
||
|
|
||
|
@ccclass
|
||
|
@disallowMultiple()
|
||
|
@menu('自定义组件/WidthAdaptor')
|
||
|
export default class WidthAdaptor extends cc.Component {
|
||
|
|
||
|
protected onLoad(): void {
|
||
|
|
||
|
let canvas = cc.Canvas.instance;
|
||
|
let ratioWidth = cc.visibleRect.width / canvas.designResolution.width;
|
||
|
if (ratioWidth >= 1) return;
|
||
|
this.node.scale = ratioWidth * this.node.scale;
|
||
|
}
|
||
|
|
||
|
}
|