ItemFix.ts
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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();
}
}