Commit b6cc7433 authored by Lwd's avatar Lwd

aaaa

parent a0fd46f2
This diff is collapsed.
......@@ -15,6 +15,18 @@ cc.Class({
type: cc.Widget,
},
bgScaleMax: {
default: [],
type: cc.Node,
displayName: "背景适配"
},
nodeUIOffset: {
default: [],
type: cc.Node,
displayName: "节点偏移"
},
canvasView: {
default: null,
type: cc.Canvas,
......@@ -38,6 +50,8 @@ cc.Class({
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
this.setBgScale();
this.setUiPositon();
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
......@@ -47,15 +61,6 @@ cc.Class({
}
}, 0);
this.MaxSize = 1;
// if (window.addEventListener) {
// window.addEventListener('resize', scaleEventCallBack, false)
// } else if (window.attachEvent) {
// window.attachEvent('resize', scaleEventCallBack, false)
// };
// g.event_mgr.reg("adjustUI", () => {
// this.init();
// });
},
init: function () {
var canvaSize = this.findCanvas();
......@@ -78,6 +83,8 @@ cc.Class({
g.data_mgr.MaxSize = this.MaxSize;
this.setUIMax(this.MaxSize);
this.settopUI(this.MaxSize);
this.setBgScale();
this.setUiPositon();
var scene = cc.director.getScene();
var list = scene.getComponentsInChildren(cc.Widget)
for (var i in list) {
......@@ -86,6 +93,7 @@ cc.Class({
},
// //屏幕缩放事件
// scaleEventCallBack: function () {
// //setTimeout(function () {
......@@ -114,6 +122,45 @@ cc.Class({
console.log(this.topUI[i].top);
}
},
//背景适配
setBgScale: function () {
for (var i in this.bgScaleMax) {
// 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值
let scaleForShowAll = Math.min(
cc.view.getCanvasSize().width / this.bgScaleMax[i].width,
cc.view.getCanvasSize().height / this.bgScaleMax[i].height
);
let realWidth = this.bgScaleMax[i].width * scaleForShowAll;
let realHeight = this.bgScaleMax[i].height * scaleForShowAll;
// 2. 基于第一步的数据,再做缩放适配
this.bgScaleMax[i].scale = Math.max(
cc.view.getCanvasSize().width / realWidth,
cc.view.getCanvasSize().height / realHeight
);
}
},
//适配节点位置
setUiPositon: function () {
for (var i in this.nodeUIOffset) {
// 1. 先找到 SHOW_ALL 模式适配之后,本节点的实际宽高以及初始缩放值
let srcScaleForShowAll = Math.min(
cc.view.getCanvasSize().width / this.nodeUIOffset[i].width,
cc.view.getCanvasSize().height / this.nodeUIOffset[i].height
);
let realWidth = this.nodeUIOffset[i].width * srcScaleForShowAll;
let realHeight = this.nodeUIOffset[i].height * srcScaleForShowAll;
// 2. 基于第一步的数据,再做节点宽高重置
this.nodeUIOffset[i].width = this.nodeUIOffset[i].width *
(cc.view.getCanvasSize().width / realWidth);
this.nodeUIOffset[i].height = this.nodeUIOffset[i].height *
(cc.view.getCanvasSize().height / realHeight);
}
},
setUIMax: function (size) {
for (var i in this.UIMax) {
if (this.UIMax[i].perScale == undefined) {
......
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