Commit 107e6107 authored by 李维's avatar 李维

优化单元页性能

parent 3ad6d7c4
...@@ -53,6 +53,23 @@ export default class NewClass extends cc.Component { ...@@ -53,6 +53,23 @@ export default class NewClass extends cc.Component {
this.initTitle(); this.initTitle();
await this.initUnitListView(); await this.initUnitListView();
this.loading.active = false; this.loading.active = false;
this.initScrollEvent();
}
// 监听滚动事件 - 将屏幕内的节点透明度恢复 - 降低Drawcall
initScrollEvent() {
const sv = cc.find("middleLayer/Views/UnitPage/unit_list_node/scrollView")
const canvas = cc.find("Canvas");
sv.on("scrolling", (e)=>{
this.allListItemNodes.forEach((node, i)=>{
const worldPos = node.parent.convertToWorldSpaceAR(cc.v2(node.x, node.y));
if(worldPos.x >= -node.width && worldPos.x <= canvas.width) {
node.opacity = 255
} else {
node.opacity = 0;
}
})
})
} }
initBg() { initBg() {
...@@ -135,6 +152,7 @@ export default class NewClass extends cc.Component { ...@@ -135,6 +152,7 @@ export default class NewClass extends cc.Component {
} }
configData = [] configData = []
allListItemNodes = [];
async initUnitListView() { async initUnitListView() {
const svNode = this.unitScrollView; const svNode = this.unitScrollView;
svNode.opacity = 0; svNode.opacity = 0;
...@@ -171,6 +189,7 @@ export default class NewClass extends cc.Component { ...@@ -171,6 +189,7 @@ export default class NewClass extends cc.Component {
view.height = svNode.height; view.height = svNode.height;
const itemArr = this.getUnitItemDataArr(rows); const itemArr = this.getUnitItemDataArr(rows);
this.allListItemNodes = itemArr;
const sv = svNode.getComponent(cc.ScrollView); const sv = svNode.getComponent(cc.ScrollView);
this.initScrollViewItem(sv, itemArr, 1); this.initScrollViewItem(sv, itemArr, 1);
...@@ -318,6 +337,10 @@ export default class NewClass extends cc.Component { ...@@ -318,6 +337,10 @@ export default class NewClass extends cc.Component {
rowCount = 0; rowCount = 0;
colCount++; colCount++;
} }
// 从第6个节点开始 透明度为0 (等滚动到屏幕内时,恢复透明度)
if(i>5) {
itemArr[i].opacity = 0;
}
} }
} }
......
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