COCOS2DX framed loading

The ScrollView (scrolling container) loading a large number of items will cause the game interface to freeze. In severe cases, the entire interface may freeze. Recently, I have encountered a problem of loading a large number of items in a rolling container. I will explain my method here, and I hope it will be helpful to everyone.
The scheme I use is summed up as follows: load items in frames.
1. Start the timer and start the refresh function every frame

local createNodeTimer = nil
< /span>function MainCtrl:startTimer()
if createNodeTimer == nil then
createNodeTimer
= cc.Director:getInstance():getScheduler():scheduleScriptFunc(ManiCtrl .update, 0, false)
end
end

2, in the refresh function body, judge whether the created item is greater than the specified number

local index = 1
local MAX_ITEM_NUMBER
= 50
function MainCtrl:update( )
if index <= MAX_ITEM_NUMBER then
self:callBack(index )
els e
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(createNodeTimer)
end
index
= index + 1
end

3, generate item

function MainCtrl:callBack(var) local oneRecordItem = self:generateOneRecordItem(var) end< /span>

local createNodeTimer = nil
function MainCtrl:startTimer()
if createNodeTimer == nil then
createNodeTimer
= cc.Director:getInstance():getScheduler():scheduleScriptFunc(ManiCtrl.update, 0, false)
end
end

local index = 1
local MAX_ITEM_NUMBER
= 50
function MainCtrl:update()
if index <= MAX_ITEM_NUMBER then
self:callBack(index)
else
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(createNodeTimer)
end
index
= index + 1
end

Leave a Comment

Your email address will not be published.