import { _decorator, Component, v3, view } from "cc"; //宽度自适应 const {ccclass, property} = _decorator; @ccclass export default class WidthAdaptor extends Component { protected onLoad(): void { let designResolutionSize = view.getDesignResolutionSize(); let frameSize = view.getViewportRect(); console.log(designResolutionSize, frameSize); let ratioWidth = designResolutionSize.height / frameSize.height; console.log(ratioWidth, designResolutionSize.width/designResolutionSize.height, frameSize.width/frameSize.height); if(designResolutionSize.width/designResolutionSize.height > frameSize.width/frameSize.height && ratioWidth>1){ //ratioWidth最大值设置为1.2 if(ratioWidth>1.1){ ratioWidth = 1.1; } console.log('ratioWidth',ratioWidth); let scale = this.node.scale this.node.scale = v3(scale.x * ratioWidth, scale.y * ratioWidth, scale.z * ratioWidth) } } // let scale = this.node.scale // this.node.scale = v3(scale.x * ratioWidth, scale.y * ratioWidth, scale.z * ratioWidth) // let canvas = cc.Canvas.instance; // let ratioWidth = cc.visibleRect.width / canvas.designResolution.width; // if (ratioWidth >= 1) return; // this.node.scale = ratioWidth * this.node.scale; }