Egret 组件顺序排列时的 drawCall 优化思路

Posted webfs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Egret 组件顺序排列时的 drawCall 优化思路相关的知识,希望对你有一定的参考价值。

竖屏项目中 垂直排序,或者 横向排序 的scoller 或者 list 组件可用

思路 :  滚动过程中, 超出 用户可视区域的部分 组件进行掩藏, 滚动到可视区域前后一定范围再进行显示

滚动事件:

this.MainList.addEventListener(eui.UIEvent.CHANGE, (e) => {}, this);

获取Scroller中某个子组件 相对于 用户可视区域的 坐标

let point = self.MainListBox.localToGlobal(item.x, item.y)

控制显示隐藏: 是用的是 <Component>.visible = <boolean>

let res;
if (point.y < 0 - item.height * 2 || point.y > self.stage.stageHeight + item.height * 2) {
    Log(item[‘floor‘], ‘需要隐藏‘, point.x, point.y)
    res = false;
} else {
    Log(item[‘floor‘], ‘需要显示‘, point.x, point.y)
    res = true;
}
item[‘showhide‘](res); //<Component>.visible = <boolean>

示例代码:

let self = this
self.MainList.addEventListener(eui.UIEvent.CHANGE, (e) => {
    self.MainListBox.$children.forEach((item, i) => {
        let point = self.MainListBox.localToGlobal(item.x, item.y)
        let res;
        if (point.y < 0 - item.height * 2 || point.y > self.stage.stageHeight + item.height * 2) {
            Log(item[‘floor‘], ‘需要隐藏‘, point.x, point.y)
            res = false;
        } else {
            Log(item[‘floor‘], ‘需要显示‘, point.x, point.y)
            res = true;
        }
        item[‘showhide‘](res);
    })
}, this);

我的项目中 测试预留前后2子组件高度即可在滚动过程中 没有卡顿

以上是关于Egret 组件顺序排列时的 drawCall 优化思路的主要内容,如果未能解决你的问题,请参考以下文章

Laya3D优化思路

Unity的Frame Debugger

Unity3D游戏开发NGUI之DrawCall数量

cocoscreator 2.4.x版本 drawcall优化 第一期(掌握控制drawcall数量的必要知识)

面试问你:你知道父子组件在执行生命周期时的顺序吗?

[LeetCode]Array主题系列