ItemFix.ts 1.58 KB
const { ccclass, property } = cc._decorator;

@ccclass
export default class ItemFix extends cc.Component {

    @property({ tooltip: "是否适配画" })
    fixHua: boolean = false;

    @property({ tooltip: "是否适配手枪" })
    fixQiang: boolean = false;

    @property({ tooltip: "是否适配手表" })
    fixBiao: boolean = false;

    @property({ tooltip: "是否适配笔记本" })
    fixBen: boolean = false;


    start() {

    }

    onLoad() {
        //卧室界面的设计尺寸是620 * 930        
        let parentNodewidth = cc.winSize.width;
        let parentNodeHeight = cc.winSize.height;
        let rW = parentNodewidth / 720;
        let rH = parentNodeHeight / 1280;
        let comp = this.getComponent(cc.Widget);
        let itemHeight = this.node.getChildByName("itemSpr").height;
        let itemWidth = this.node.getChildByName("itemSpr").width;
        if (this.fixHua) {
            comp.top = (parentNodeHeight / 2) - (280 * rH) - (itemHeight * rH / 2);
            if (rH < 1) {
                this.node.scale = 0.8;
                comp.left = itemWidth * 0.8 / 2;
            } else {
                comp.left = itemWidth / 2;
            }
        }
        if (this.fixQiang) {
            comp.top = (parentNodeHeight / 2) + 50
            comp.left = comp.left * rW;
        }
        if (this.fixBiao) {
            comp.right = comp.right * rW;
            comp.bottom = comp.bottom * rH;
        }
        if (this.fixBen) {
            comp.right = comp.right * rW;
            comp.bottom = comp.bottom * rH;
        }
        comp.updateAlignment();
    }
}