Files
slide_block/assets/scripts/utils/ScreenAdapter.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

1970-01-01 08:27:52 +08:00
// ScreenAdapter.ts
import { _decorator, Component, view, ResolutionPolicy } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('ScreenAdapter')
export class ScreenAdapter extends Component {
@property
designWidth: number = 1080; // 默认设计宽度
@property
designHeight: number = 1920; // 默认设计高度
onLoad() {
this.applyAdapter();
}
/**
*
*/
applyAdapter() {
// const frameSize = view.getFrameSize();
// const aspect = frameSize.width / frameSize.height;
// const designAspect = this.designWidth / this.designHeight;
// if (aspect > designAspect) {
// // 屏幕更宽 → 固定高度,保证上下完整
// view.setDesignResolutionSize(this.designWidth, this.designHeight, ResolutionPolicy.FIXED_HEIGHT);
// console.log('[ScreenAdapter] Use FIXED_HEIGHT, aspect =', aspect.toFixed(2));
// } else {
// // 屏幕更窄 → 固定宽度,保证左右完整
// view.setDesignResolutionSize(this.designWidth, this.designHeight, ResolutionPolicy.FIXED_WIDTH);
// console.log('[ScreenAdapter] Use FIXED_WIDTH, aspect =', aspect.toFixed(2));
// }
}
}