8baa0bd2-9a17-485b-8606-69641bc6112e.js 2.77 KB
"use strict";
cc._RF.push(module, '8baa0vSmhdIW4YGaWQbxhEu', 'PortraitFixComponent');
// script/common/components/PortraitFixComponent.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const GameConfig_1 = require("../../GameConfig");
const { ccclass, property } = cc._decorator;
let PortraitFixComponent = /** @class */ (() => {
    let PortraitFixComponent = class PortraitFixComponent extends cc.Component {
        onLoad() {
        }
        start() {
        }
        update(dt) {
        }
        /**屏幕适配 */
        fixScreenSize(isDatingScene) {
            let sprComp = this.node.getComponent(cc.Sprite);
            if (!sprComp) {
                cc.error("the PortraitFixComponent node has no cc.Sprite Component !");
                return;
            }
            let spriteFrame = sprComp.spriteFrame;
            if (!spriteFrame) {
                cc.warn("the cc.Sprite Component with empty spriteFrame data !");
                return;
            }
            this.node.stopAllActions();
            let spriteFrameRect = spriteFrame.getRect();
            let screenSize = cc.winSize;
            let rW = screenSize.width / spriteFrameRect.width;
            let rH = screenSize.height / spriteFrameRect.height;
            if (GameConfig_1.GameConfig.debug) {
                // console.log("screenSize.width & spriteFrameRect.width", screenSize.width + ", " + spriteFrameRect.width);
                // console.log("screenSize.height & spriteFrameRect.height", screenSize.height + ", " + spriteFrameRect.height);
                // console.log("rW & rH", rW + ", " + rH);
            }
            if (rW >= 1 && rH >= 1) {
                return;
            }
            let s = 0;
            if (isDatingScene) {
                s = Math.min(rW, rH, 1, 0.73);
            }
            else {
                s = Math.min(rW, rH, 0.7);
            }
            if (GameConfig_1.GameConfig.debug) {
                console.log("this.node.scale", s);
            }
            this.node.scale = s;
        }
    };
    PortraitFixComponent = __decorate([
        ccclass
    ], PortraitFixComponent);
    return PortraitFixComponent;
})();
exports.default = PortraitFixComponent;

cc._RF.pop();