mirror of
https://github.com/Gongxh0901/kunpolibrary
synced 2025-05-15 14:54:25 +00:00
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
|
/**
|
||
|
* @Author: Gongxh
|
||
|
* @Date: 2024-12-08
|
||
|
* @Description:
|
||
|
*/
|
||
|
|
||
|
import { screen as ccScreen, view } from "cc";
|
||
|
import { Adapter } from "../global/Adapter";
|
||
|
import { size } from "../global/header";
|
||
|
import { info } from "../tool/log";
|
||
|
|
||
|
export class CocosAdapter extends Adapter {
|
||
|
/**
|
||
|
* 获取屏幕像素尺寸
|
||
|
* @returns {size}
|
||
|
*/
|
||
|
protected getScreenSize(): size {
|
||
|
let windowSize = ccScreen.windowSize;
|
||
|
let width = Math.ceil(windowSize.width / view.getScaleX());
|
||
|
let height = Math.ceil(windowSize.height / view.getScaleY());
|
||
|
return { width, height };
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取设计尺寸
|
||
|
* @returns {size}
|
||
|
*/
|
||
|
protected getDesignSize(): size {
|
||
|
let designSize = view.getDesignResolutionSize();
|
||
|
return { width: designSize.width, height: designSize.height };
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 设置尺寸发生变化的监听
|
||
|
* @param callback
|
||
|
*/
|
||
|
protected registerResizeCallback(callback: (...args: any) => void): void {
|
||
|
ccScreen.on("window-resize", (...args: any) => {
|
||
|
info("window-resize");
|
||
|
callback(...args);
|
||
|
}, this);
|
||
|
ccScreen.on("orientation-change", (...args: any) => {
|
||
|
info("orientation-change");
|
||
|
callback(...args);
|
||
|
}, this);
|
||
|
ccScreen.on("fullscreen-change", (...args: any) => {
|
||
|
info("fullscreen-change");
|
||
|
callback(...args);
|
||
|
}, this);
|
||
|
}
|
||
|
}
|