Commit e44191d5 authored by limingzhe's avatar limingzhe

fix: 修改尺寸

parent 874a9214
{ {"ver":"1.1.2","uuid":"551f3197-dce7-4bd2-a290-e784ab1d271a","isBundle":false,"bundleName":"","priority":1,"compressionType":{},"optimizeHotUpdate":{},"inlineSpriteFrames":{},"isRemoteBundle":{"ios":false,"android":false},"subMetas":{}}
"ver": "1.1.2", \ No newline at end of file
"uuid": "551f3197-dce7-4bd2-a290-e784ab1d271a",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {
"ios": false,
"android": false
},
"subMetas": {}
}
\ No newline at end of file
...@@ -559,7 +559,7 @@ ...@@ -559,7 +559,7 @@
"_enabled": true, "_enabled": true,
"alignMode": 2, "alignMode": 2,
"_target": null, "_target": null,
"_alignFlags": 44, "_alignFlags": 4,
"_left": 0, "_left": 0,
"_right": 0, "_right": 0,
"_top": 0, "_top": 0,
......
...@@ -43,12 +43,12 @@ var game = cc.Class({ ...@@ -43,12 +43,12 @@ var game = cc.Class({
//初始化游戏 //初始化游戏
this.initGame(); this.initGame();
//监听尺寸变化 // //监听尺寸变化
if (window.addEventListener) { // if (window.addEventListener) {
window.addEventListener('resize', this.scaleEventCallBack, false) // window.addEventListener('resize', this.scaleEventCallBack, false)
} else if (window.attachEvent) { // } else if (window.attachEvent) {
window.attachEvent('resize', this.scaleEventCallBack, false) // window.attachEvent('resize', this.scaleEventCallBack, false)
} // }
}, },
//屏幕缩放 //屏幕缩放
......
...@@ -43,14 +43,16 @@ cc.Class({ ...@@ -43,14 +43,16 @@ cc.Class({
onLoad: function () { //开启适配 onLoad: function () { //开启适配
this.widgetList = []; this.widgetList = [];
this.initSize();
this.scheduleOnce(function () { this.scheduleOnce(function () {
if (!this.isCanvas) { if (!this.isCanvas) {
this.init(); this.init();
} else { } else {
var canvaSize = this.findCanvas(); // var canvaSize = this.findCanvas();
var w = (canvaSize.width) / HEIGTH; // var w = (canvaSize.width) / HEIGTH;
var h = (canvaSize.height) / WIDTH; // var h = (canvaSize.height) / WIDTH;
this.MaxSize = w / h > 1 ? w / h : h / w; this.MaxSize = 1 //w / h > 1 ? w / h : h / w;
this.setUIMax(this.MaxSize); this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize); this.settopUI(this.MaxSize);
...@@ -60,7 +62,7 @@ cc.Class({ ...@@ -60,7 +62,7 @@ cc.Class({
var list = scene.getComponentsInChildren(cc.Widget) var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) { for (var i in list) {
list[i].updateAlignment(); // list[i].updateAlignment();
} }
} }
}, 0); }, 0);
...@@ -71,23 +73,51 @@ cc.Class({ ...@@ -71,23 +73,51 @@ cc.Class({
}); });
this.MaxSize = 1; this.MaxSize = 1;
}, },
initSize() {
// 注意cc.winSize只有在适配后(修改fitHeight/fitWidth后)才能获取到正确的值,因此使用cc.getFrameSize()来获取初始的屏幕大小
let screen_size = cc.view.getFrameSize().width / cc.view.getFrameSize().height
let design_size = cc.Canvas.instance.designResolution.width / cc.Canvas.instance.designResolution.height
let f = screen_size >= design_size
cc.Canvas.instance.fitHeight = f
cc.Canvas.instance.fitWidth = !f
const frameSize = cc.view.getFrameSize();
this._frameSize = frameSize;
this._designSize = cc.view.getDesignResolutionSize();
let sx = cc.winSize.width / frameSize.width;
let sy = cc.winSize.height / frameSize.height;
this._cocosScale = Math.min(sx, sy);
sx = frameSize.width / this._designSize.width;
sy = frameSize.height / this._designSize.height;
this._mapScaleMin = Math.min(sx, sy) * this._cocosScale;
this._mapScaleMax = Math.max(sx, sy) * this._cocosScale;
this.canvas = cc.find("Canvas");
},
init: function () { init: function () {
var canvaSize = this.findCanvas(); // var canvaSize = this.findCanvas();
var diff = canvaSize.width / canvaSize.height; // var diff = canvaSize.width / canvaSize.height;
var bili = WIDTH / HEIGTH; // var bili = WIDTH / HEIGTH;
if (diff > bili) { // if (diff > bili) {
this.canvasView.fitWidth = false; // this.canvasView.fitWidth = false;
this.canvasView.fitHeight = true; // this.canvasView.fitHeight = true;
} else if (diff < bili) { // } else if (diff < bili) {
this.canvasView.fitWidth = true; // this.canvasView.fitWidth = true;
this.canvasView.fitHeight = false; // this.canvasView.fitHeight = false;
} else { // } else {
this.canvasView.fitWidth = true; // this.canvasView.fitWidth = true;
this.canvasView.fitHeight = true; // this.canvasView.fitHeight = true;
} // }
var w = (canvaSize.width) / WIDTH; // var w = (canvaSize.width) / WIDTH;
var h = (canvaSize.height) / HEIGTH; // var h = (canvaSize.height) / HEIGTH;
this.MaxSize = w / h > 1 ? w / h : h / w; this.MaxSize = 1 // w / h > 1 ? w / h : h / w;
LWD_3.data_mgr.MaxSize = this.MaxSize; LWD_3.data_mgr.MaxSize = this.MaxSize;
this.setUIMax(this.MaxSize); this.setUIMax(this.MaxSize);
...@@ -97,7 +127,7 @@ cc.Class({ ...@@ -97,7 +127,7 @@ cc.Class({
var scene = cc.director.getScene(); var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget) var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) { for (var i in list) {
list[i].updateAlignment(); // list[i].updateAlignment();
} }
}, },
...@@ -126,6 +156,16 @@ cc.Class({ ...@@ -126,6 +156,16 @@ cc.Class({
//背景适配 //背景适配
setBgScale: function () { setBgScale: function () {
const bg = cc.find('Canvas/bg');
bg.scale = this._mapScaleMax;
const grass = cc.find('Canvas/connent/bg_grass');
grass.scaleX = this.canvas.width / grass.width;
return;
for (var i in this.bgScaleMax) { for (var i in this.bgScaleMax) {
// 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值 // 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值
let scaleForShowAll = Math.min( let scaleForShowAll = Math.min(
...@@ -145,6 +185,7 @@ cc.Class({ ...@@ -145,6 +185,7 @@ cc.Class({
//适配节点位置 //适配节点位置
setUiPositon: function () { setUiPositon: function () {
return;
for (var i in this.nodeUIOffset) { for (var i in this.nodeUIOffset) {
// 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值 // 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值
let srcScaleForShowAll = Math.min( let srcScaleForShowAll = Math.min(
...@@ -161,6 +202,7 @@ cc.Class({ ...@@ -161,6 +202,7 @@ cc.Class({
}, },
setUIMax: function (size) { setUIMax: function (size) {
return;
for (var i in this.UIMax) { for (var i in this.UIMax) {
if (this.UIMax[i].perScale == undefined) { if (this.UIMax[i].perScale == undefined) {
this.UIMax[i].perScale = this.UIMax[i].scaleX; this.UIMax[i].perScale = this.UIMax[i].scaleX;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment