Commit 9194fbdb authored by 范雪寒's avatar 范雪寒

feat:

parent 396d96dd
...@@ -5,6 +5,7 @@ import { initResMgr_NGT_02 } from "../manager/res_mgr"; ...@@ -5,6 +5,7 @@ import { initResMgr_NGT_02 } from "../manager/res_mgr";
import { initSndMgr_NGT_02 } from "../manager/snd_mgr"; import { initSndMgr_NGT_02 } from "../manager/snd_mgr";
import { initUtils_NGT_02 } from "./utils"; import { initUtils_NGT_02 } from "./utils";
import { initEnumMgr_NGT_02 } from "../game/speaker"; import { initEnumMgr_NGT_02 } from "../game/speaker";
// 全局环境预声明 // 全局环境预声明
export function initGlobal_NGT_02() { export function initGlobal_NGT_02() {
console.log('window.g init'); console.log('window.g init');
......
import { initGlobal_NGT_02 } from "./_preDefine";
/** /**
* 适配 * 适配
*/ */
...@@ -8,7 +9,7 @@ cc.Class({ ...@@ -8,7 +9,7 @@ cc.Class({
UIMax: { UIMax: {
default: [], default: [],
type: cc.Node, type: cc.Node,
displayName: "等比放大" displayName: "等比放大",
}, },
topUI: { topUI: {
default: [], default: [],
...@@ -18,26 +19,29 @@ cc.Class({ ...@@ -18,26 +19,29 @@ cc.Class({
bgScaleMax: { bgScaleMax: {
default: [], default: [],
type: cc.Node, type: cc.Node,
displayName: "背景适配" displayName: "背景适配",
}, },
nodeUIOffset: { nodeUIOffset: {
default: [], default: [],
type: cc.Node, type: cc.Node,
displayName: "节点偏移" displayName: "节点偏移",
}, },
canvasView: { canvasView: {
default: null, default: null,
type: cc.Canvas, type: cc.Canvas,
displayName: "根节点" displayName: "根节点",
}, },
isCanvas: { isCanvas: {
default: false, default: false,
} },
}, },
onLoad: function () { //开启适配 onLoad: function () {
initGlobal_NGT_02();
//开启适配
this.widgetList = []; this.widgetList = [];
this.scheduleOnce(function () { this.scheduleOnce(function () {
...@@ -45,8 +49,8 @@ cc.Class({ ...@@ -45,8 +49,8 @@ cc.Class({
this.init(); this.init();
} else { } else {
var canvaSize = this.findCanvas(); var canvaSize = this.findCanvas();
var w = (canvaSize.width) / 720; var w = canvaSize.width / 720;
var h = (canvaSize.height) / 1280; var h = canvaSize.height / 1280;
this.MaxSize = w / h > 1 ? w / h : h / w; this.MaxSize = w / h > 1 ? w / h : h / w;
this.setUIMax(this.MaxSize); this.setUIMax(this.MaxSize);
...@@ -55,7 +59,7 @@ cc.Class({ ...@@ -55,7 +59,7 @@ cc.Class({
this.setUiPositon(); this.setUiPositon();
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();
} }
...@@ -85,8 +89,8 @@ cc.Class({ ...@@ -85,8 +89,8 @@ cc.Class({
this.canvasView.fitWidth = true; this.canvasView.fitWidth = true;
this.canvasView.fitHeight = true; this.canvasView.fitHeight = true;
} }
var w = (canvaSize.width) / 750; var w = canvaSize.width / 750;
var h = (canvaSize.height) / 1334; var h = canvaSize.height / 1334;
this.MaxSize = w / h > 1 ? w / h : h / w; this.MaxSize = w / h > 1 ? w / h : h / w;
g.data_mgr.MaxSize = this.MaxSize; g.data_mgr.MaxSize = this.MaxSize;
...@@ -95,7 +99,7 @@ cc.Class({ ...@@ -95,7 +99,7 @@ cc.Class({
this.setBgScale(); this.setBgScale();
this.setUiPositon(); this.setUiPositon();
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();
} }
...@@ -115,7 +119,6 @@ cc.Class({ ...@@ -115,7 +119,6 @@ cc.Class({
for (var i in this.topUI) { for (var i in this.topUI) {
if (this.topUI[i].perTop == undefined) { if (this.topUI[i].perTop == undefined) {
this.topUI[i].perTop = this.topUI[i].top; this.topUI[i].perTop = this.topUI[i].top;
} else { } else {
this.topUI[i].top = this.topUI[i].perTop; this.topUI[i].top = this.topUI[i].perTop;
} }
...@@ -155,8 +158,10 @@ cc.Class({ ...@@ -155,8 +158,10 @@ cc.Class({
let realHeight = 720 * srcScaleForShowAll; let realHeight = 720 * srcScaleForShowAll;
// 2. 基于第一步的数据,再做节点宽高重置 // 2. 基于第一步的数据,再做节点宽高重置
this.nodeUIOffset[i].width = 1280 * (cc.view.getCanvasSize().width / realWidth); this.nodeUIOffset[i].width =
this.nodeUIOffset[i].height = 720 * (cc.view.getCanvasSize().height / realHeight); 1280 * (cc.view.getCanvasSize().width / realWidth);
this.nodeUIOffset[i].height =
720 * (cc.view.getCanvasSize().height / realHeight);
} }
}, },
...@@ -164,7 +169,6 @@ cc.Class({ ...@@ -164,7 +169,6 @@ cc.Class({
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;
} else { } else {
this.UIMax[i].scaleX = this.UIMax[i].perScale; this.UIMax[i].scaleX = this.UIMax[i].perScale;
this.UIMax[i].scaleY = this.UIMax[i].perScale; this.UIMax[i].scaleY = this.UIMax[i].perScale;
...@@ -177,13 +181,13 @@ cc.Class({ ...@@ -177,13 +181,13 @@ cc.Class({
if (cc.sys.isNative) { if (cc.sys.isNative) {
return { return {
width: cc.view.getFrameSize().width, width: cc.view.getFrameSize().width,
height: cc.view.getFrameSize().height height: cc.view.getFrameSize().height,
}; };
} else { } else {
return { return {
width: cc.game.canvas.clientWidth, width: cc.game.canvas.clientWidth,
height: cc.game.canvas.clientHeight height: cc.game.canvas.clientHeight,
}; };
} }
} },
}); });
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