cocos2d-x分帧加载资源

本文介绍了一种在游戏中实现资源渐进加载的方法,通过每四帧加载一次资源的方式,避免了游戏启动时的大规模资源加载导致的延迟,提高了游戏的流畅性和用户体验。此方法使用Lua脚本控制,通过cc.SpriteFrameCache接口加载精灵帧,实现了资源的平滑加载。

function GameApp:updateLoadRes()
    
    local PLIST_FILE = {
        "plist/beforeGameAni.plist",
        "plist/item.plist",
        "plist/addsub_ani.plist",
        "plist/other_ani.plist",
        "plist/po_ani.plist",
        "plist/tractor_ani.plist",
        "plist/prop.plist",
        "plist/match.plist",
        "plist/box.plist",
        "plist/count.plist",
    }
    
    local loadResNum = 0
    local updateTimes = 0
    local nowLoadNums = 0
    local scheduleListener = 0
    local function updateLoad(dt)
        updateTimes = updateTimes + 1
        if updateTimes % 4 == 0 then   --每四帧加载一次
            nowLoadNums = nowLoadNums + 1
            
            cc.SpriteFrameCache:getInstance():addSpriteFrames(PLIST_FILE[nowLoadNums])
            if #PLIST_FILE <= nowLoadNums then
                cc.Director:getInstance():getScheduler():unscheduleScriptEntry(scheduleListener)
                scheduleListener = nil
            end

        end
    end
    
    scheduleListener = cc.Director:getInstance():getScheduler():scheduleScriptFunc(updateLoad , 0 , false)
end

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值