import { _decorator, Component, ResolutionPolicy, UITransform, view } from 'cc'; const { ccclass } = _decorator; /** 保持完整设计画布;装饰背景等比覆盖额外区域。 / Preserve the entire design canvas and cover extra space with the decorative backdrop. */ @ccclass('WelcomeViewport') export class WelcomeViewport extends Component { private frameKey = ''; onEnable(): void { this.fit(); } update(): void { this.fit(); } private fit(): void { const frame = view.getFrameSize(); if (frame.width <= 0 || frame.height <= 0) return; const key = `${frame.width}:${frame.height}`; if (key === this.frameKey) return; this.frameKey = key; const short = frame.height / frame.width < 1920 / 1080; view.setDesignResolutionSize(1080, 1920, short ? ResolutionPolicy.FIXED_HEIGHT : ResolutionPolicy.FIXED_WIDTH); const visible = view.getVisibleSize(); // 主体切图保持原设计坐标,只有背景按覆盖比例放大。 / Keep foreground design coordinates and scale only the background to cover. this.node.getComponent(UITransform)?.setContentSize(visible); const cover = Math.max(visible.width / 1080, visible.height / 1920); this.node.getChildByName('OrchardBackdrop')?.setScale(cover, cover, 1); } }