cocos_lua listView加载超多数据

这篇博客介绍了如何使用Lua实现一个QuickCell类,优化Cocos2d-x ListView加载大量数据的性能。通过创建可复用的Cell并根据视口位置动态进入和退出,减少了内存消耗和渲染负担。在另一文件中展示了如何在ActivityLayer中初始化UI,并创建及更新ListView的Cell。
摘要由CSDN通过智能技术生成

创建QuickCell文件 
local QuickCell = class("QuickCell", function() 
    return ccui.Widget:create() 
end)

-- self._data.wid               default 100
-- self._data.hei               default 50
-- self._data.anchor            default {x=0, y=0}
-- self._data.tick_interval     default 0.02
-- self._data.activeEvent       default inview
-- self._data.createCell        default nil

function QuickCell:ctor()
    self._entered = false
    self._active = true
end

function QuickCell:Create( data )
    local cell = QuickCell.new()
    if cell and cell:Init( data ) then
        return cell
    end

    return nil
end

function QuickCell:Init( data )
    self._data = data

    local wid = self._data.wid or 100
    local hei = self._data.hei or 50
    local anchor = self._data.anchor or {x=0, y=0}

    self:setContentSize( {width = wid, height = hei} )
    self:setAnchorPoint( anchor )

    self:Active()

    return true
end

function QuickCell:Update( data )
    local createCell = data.createCell
    self._data.createCell &

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值