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": {}
}
\ No newline at end of file
{"ver":"1.1.2","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 @@
"_enabled": true,
"alignMode": 2,
"_target": null,
"_alignFlags": 44,
"_alignFlags": 4,
"_left": 0,
"_right": 0,
"_top": 0,
......
......@@ -43,12 +43,12 @@ var game = cc.Class({
//初始化游戏
this.initGame();
//监听尺寸变化
if (window.addEventListener) {
window.addEventListener('resize', this.scaleEventCallBack, false)
} else if (window.attachEvent) {
window.attachEvent('resize', this.scaleEventCallBack, false)
}
// //监听尺寸变化
// if (window.addEventListener) {
// window.addEventListener('resize', this.scaleEventCallBack, false)
// } else if (window.attachEvent) {
// window.attachEvent('resize', this.scaleEventCallBack, false)
// }
},
//屏幕缩放
......
......@@ -43,14 +43,16 @@ cc.Class({
onLoad: function () { //开启适配
this.widgetList = [];
this.initSize();
this.scheduleOnce(function () {
if (!this.isCanvas) {
this.init();
} else {
var canvaSize = this.findCanvas();
var w = (canvaSize.width) / HEIGTH;
var h = (canvaSize.height) / WIDTH;
this.MaxSize = w / h > 1 ? w / h : h / w;
// var canvaSize = this.findCanvas();
// var w = (canvaSize.width) / HEIGTH;
// var h = (canvaSize.height) / WIDTH;
this.MaxSize = 1 //w / h > 1 ? w / h : h / w;
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
......@@ -60,7 +62,7 @@ cc.Class({
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
// list[i].updateAlignment();
}
}
}, 0);
......@@ -71,23 +73,51 @@ cc.Class({
});
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 () {
var canvaSize = this.findCanvas();
var diff = canvaSize.width / canvaSize.height;
var bili = WIDTH / HEIGTH;
if (diff > bili) {
this.canvasView.fitWidth = false;
this.canvasView.fitHeight = true;
} else if (diff < bili) {
this.canvasView.fitWidth = true;
this.canvasView.fitHeight = false;
} else {
this.canvasView.fitWidth = true;
this.canvasView.fitHeight = true;
}
var w = (canvaSize.width) / WIDTH;
var h = (canvaSize.height) / HEIGTH;
this.MaxSize = w / h > 1 ? w / h : h / w;
// var canvaSize = this.findCanvas();
// var diff = canvaSize.width / canvaSize.height;
// var bili = WIDTH / HEIGTH;
// if (diff > bili) {
// this.canvasView.fitWidth = false;
// this.canvasView.fitHeight = true;
// } else if (diff < bili) {
// this.canvasView.fitWidth = true;
// this.canvasView.fitHeight = false;
// } else {
// this.canvasView.fitWidth = true;
// this.canvasView.fitHeight = true;
// }
// var w = (canvaSize.width) / WIDTH;
// var h = (canvaSize.height) / HEIGTH;
this.MaxSize = 1 // w / h > 1 ? w / h : h / w;
LWD_3.data_mgr.MaxSize = this.MaxSize;
this.setUIMax(this.MaxSize);
......@@ -97,7 +127,7 @@ cc.Class({
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
list[i].updateAlignment();
// list[i].updateAlignment();
}
},
......@@ -126,6 +156,16 @@ cc.Class({
//背景适配
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) {
// 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值
let scaleForShowAll = Math.min(
......@@ -145,6 +185,7 @@ cc.Class({
//适配节点位置
setUiPositon: function () {
return;
for (var i in this.nodeUIOffset) {
// 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值
let srcScaleForShowAll = Math.min(
......@@ -161,6 +202,7 @@ cc.Class({
},
setUIMax: function (size) {
return;
for (var i in this.UIMax) {
if (this.UIMax[i].perScale == undefined) {
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