zoukankan      html  css  js  c++  java
  • Laya 使list渲染支持分帧的思路

    Laya 使list渲染支持分帧的思路

    @author ixenos 2019-09-06

    1.由于Laya的list渲染时没有做分帧处理,只做了延迟帧处理,所以当单页元素较多时,会有大量运算卡帧的情况,

    结合之前 Laya 分帧加载优化 这篇文章,对其中renderItems做出优化

    2.原renderItems:

     1         /**
     2          * @private
     3          * 渲染单元格列表。
     4          */
     5         protected function renderItems(from:int = 0, to:int = 0):void {
     6             for (var i:int = from, n:int = to || _cells.length; i < n; i++) {
     7                 renderItem(_cells[i], _startIndex + i);
     8             }
     9             changeSelectStatus();
    10         }

    3.分帧方案:

     1         private var _latterFrom:int = 0;
     2         private var _latterTo:int = 0;
     3         protected function renderItems(from:int = 0, to:int = 0):void {
     4             _latterFrom = from;
     5             _latterTo = to;
     6             Laya.timer.clear(this, onLatterFrames);
     7             Laya.timer.frameLoop(1, this, onLatterFrames);
     8         }
     9         
    10         private var _renderSt:Number = 0;
    11         private var _renderTLimit:Number = 0;
    12         public var latterFrameRatio:Number = 0.8;//运行时脚本占帧时间比,这个用来调优 --ixenos
    13         protected function onLatterFrames():void {
    14             _renderTLimit = 1000/60*latterFrameRatio;
    15             _renderSt = new Date().getTime();
    16             _latterTo = _latterTo>0?_latterTo:_cells.length;
    17             for (var i:int = _latterFrom; i < _latterTo; i++) {
    18                 var curT:Number = new Date().getTime();
    19                 if(curT - _renderSt > _renderTLimit){
    20                     _latterFrom = i;//暂存进度
    21                     return;
    22                 }
    23                 renderItem(_cells[i], _startIndex + i);
    24                 changeCellState(_cells[i], _selectedIndex === _startIndex + i, 1);
    25             }
    26             Laya.timer.clear(this, onLatterFrames);
    27         }
     
  • 相关阅读:
    MyString
    Django疑难问题
    mysql 疑难问题-django
    python时间转换 ticks-FYI
    django建议入门-FYI
    Python风格规范-FYI
    scrum敏捷开发☞
    git基本命令
    centos下的安装mysql,jdk
    memcached for .net on windows
  • 原文地址:https://www.cnblogs.com/ixenos/p/11477296.html
Copyright © 2011-2022 走看看