calScreenSize: function () {
let screenSize = cc.view.getFrameSize();
let ratio = screenSize.width / screenSize.height;
let size = cc.view.getDesignResolutionSize();
let min = Math.min(size.width, size.height);
let max = Math.max(size.width, size.height);
let clacRatio = ratio <= 1 ? ratio : (screenSize.height / screenSize.width);
let fitSize = Math.round(min / clacRatio);
this._designSize = {
min: min,
max: max
};
this._screenSize = cc.size(min, fitSize);
// console.log('design:', this._designSize, 'screen:', this._screenSize);
},
//监听横竖品
hengshu: function () {
// console.log("判断横竖")
let screen1 = cc.view.getFrameSize();
// console.log("width:" + screen.width + " height:" + screen.height)
let ratio1 = screen1.width / screen1.height;
this.dealScreen(ratio1);
let self = this;
window.onresize = function () {
let screen2 = cc.view.getFrameSize();
let ratio2 = screen2.width / screen2.height;
self.dealScreen(ratio2);
}
},
//横竖屏的处理
dealScreen: function (ratio) {
// console.log('横竖屏的处理:', ratio)
this.ratio = ratio;
if (ratio <= 1) { //竖屏
// console.log('竖屏')
cc.view.setDesignResolutionSize(this._designSize.min, this._designSize.max, cc.ResolutionPolicy.FIXED_WIDTH);
this.canvas.node.setPosition(cc.v2(this._screenSize.width / 2, this._screenSize.height / 2));
this.canvas.node.setContentSize(this._screenSize.width, this._screenSize.height);
this.bgNode_shu.setContentSize(this._screenSize.width, this._screenSize.height);
this.bgNode_shu.setPosition(0, 0);
this.alertMask_shu.setContentSize(this._screenSize.width, this._screenSize.height);
this.alertMask_shu.setPosition(0, 0);
this.bgNode_shu.active = true;
this.bgNode_heng.active = false;
this.alertMask_shu.active = true;
this.alertMask_heng.active = false;
this.numZoneKuang.active = false;
this.selectedBg.getComponent(cc.Sprite).spriteFrame = this.selectBgSpic[0];
this.selectedBg.width = 79;
this.selectedBg.height = 79;
this.node.setPosition(-351.5, 470);
if (ratio >= 0.75) { //主要是ipad
this.node.parent.scale = 0.7;
}
this.title.setPosition(0, 555);
this.downloadNode.setPosition(0, -450);
this.numZoneLayout.setPosition(-360, -320);
// let num1 = this.numZoneLayout.getChildByName("1");
// let num2 = this.numZoneLayout.getChildByName("2");
// let num3 = this.numZoneLayout.getChildByName("3");
// let num4 = this.numZoneLayout.getChildByName("4");
// let num5 = this.numZoneLayout.getChildByName("5");
// let num6 = this.numZoneLayout.getChildByName("6");
// let num7 = this.numZoneLayout.getChildByName("7");
// let num8 = this.numZoneLayout.getChildByName("8");
// let num9 = this.numZoneLayout.getChildByName("9");
// num1.setPosition(120, 0);
// num2.setPosition(280, 0);
// num3.setPosition(440, 0);
// num4.setPosition(600, 0);
for (let c = 1; c <= 9; c++) {
let el = c;
let node = this.numZoneLayout.getChildByName(`${el}`);
let pos = cc.v2(4.5 + 79 / 2 + 79 * (el - 1), 0);
node.setPosition(pos);
}
this.showFinger();
this.endPageShu(ratio);
} else {
// console.log('横屏')
cc.view.setDesignResolutionSize(this._designSize.max, this._designSize.min, cc.ResolutionPolicy.FIXED_HEIGHT);
this.canvas.node.setPosition(cc.v2(this._screenSize.height / 2, this._screenSize.width / 2));
this.canvas.node.setContentSize(this._screenSize.height, this._screenSize.width);
this.bgNode_heng.setContentSize(this._screenSize.height, this._screenSize.width);
this.bgNode_heng.setPosition(0, 0);
this.alertMask_heng.setContentSize(this._screenSize.height, this._screenSize.width);
this.alertMask_heng.setPosition(0, 0);
this.bgNode_shu.active = false;
this.bgNode_heng.active = true;
this.alertMask_shu.active = false;
this.alertMask_heng.active = true;
this.numZoneKuang.active = true;
this.selectedBg.getComponent(cc.Sprite).spriteFrame = this.selectBgSpic[1];
this.selectedBg.width = 130;
this.selectedBg.height = 100;
let pos_add = 0;
if (ratio < 2) {
// console.log("分辨率大于1,小于2")
this.node.parent.scale = 0.7;
} else { //主要是ipx
// console.log("分辨率大于等于2")
this.node.parent.scale = 0.8;
pos_add = 45;
}
this.node.setPosition(-585, 351.5 + pos_add);
this.title.setPosition(400, 265 + pos_add);
this.downloadNode.setPosition(400, -225 + pos_add);
this.numZoneLayout.setPosition(200, 193 + pos_add);
// let num1 = this.numZoneLayout.getChildByName("1");
// let num2 = this.numZoneLayout.getChildByName("2");
// let num3 = this.numZoneLayout.getChildByName("3");
// let num4 = this.numZoneLayout.getChildByName("4");
// num1.setPosition(85, 85);
// num2.setPosition(260, 85);
// num3.setPosition(90, -85);
// num4.setPosition(260, -85);
let bBetween = 4;
let SBetween = 2;
let width = 130;
let height = 100;
for (let c = 1; c <= 3; c++) {
for (let c1 = 1; c1 <= 3; c1++) {
let el = (c - 1) * 3 + c1;
let node = this.numZoneLayout.getChildByName(`${el}`);
let x = bBetween + 130 / 2 + (SBetween + width) * (c1 - 1);
let y = bBetween + height / 2 + (bBetween + height) * (c - 1)
let pos = cc.v2(x, -y);
node.setPosition(pos);
}
}
this.showFinger();
this.endPageHeng(ratio);
}
},