cocos creator,AdapterScale适配组件
const { ccclass } = cc._decorator;
@ccclass
export default class AdapterScale extends cc.Component {
onLoad() {
const _desWidth = cc.view.getDesignResolutionSize().width;
const _desHeight = cc.view.getDesignResolutionSize().height;
const _realWidth = cc.view.getVisibleSizeInPixel().width;
const _realHeight = cc.view.getVisibleSizeInPixel().height;
const _ratioDes = _desWidth / _desHeight;
const _ratioReal = _realWidth / _realHeight;
if (_ratioReal < _ratioDes) {
this.node.scale = _ratioReal / _ratioDes * this.node.scale;
}
}
}