加载UI工程的csb,以及纹理缓存情况

以plist+PNG模式加载csb,并播放UI工程做的动画,用法如下

local Layer = cc.CSLoader:createNode("res/yk/interface/loading.csb")
local Action = cc.CSLoader:createTimeline("res/yk/interface/loading.csb")    --序列帧动画
Layer:runAction(Action)
--Action:setTimeSpeed(10/60)
Action:gotoFrameAndPlay(0, true)
scene:addChild(Layer, 1)

 

这种模式下,不用预先加载plist,加载csb时会自动加载,预先加载的话会重复加载,但是可以通过清缓存清理掉一个

 

以下是测试时用的代码

cc.FileUtils:getInstance():addSearchPath("res/yk")

function MainSence:RefreshLayer(scene) 

    self.scene = scene--    local cache = cc.SpriteFrameCache:getInstance();
--    cache:addSpriteFrames("res/yk/china/loading.plist")

    local test = cc.Node:create()
    scene:addChild(test)

    for i=1,8 do
        performWithDelay(test,function()self:add(i) end,i)
    end
end

function MainSence:add(key)
    --print("加载plist")
    --print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
    print("key "..key)

    if key == 6 then
        for i=1,5 do
            self.scene:removeChildByTag(i)
        end
        print("移除所有元素")
        print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
    end
    if key == 7 then
        print("移除元素后 清缓存")
        cc.Director:getInstance():getTextureCache():removeUnusedTextures()
        print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
    end
    
    if key < 6 then
        local layout = ccui.Layout:create()
        layout:setContentSize(cc.size(SCREEN_WIDTH, SCREEN_HEIGHT))
        layout:setTouchEnabled(true)
        layout:setAnchorPoint(cc.p(0, 0))
        layout:setPosition(cc.p(0, 0))
        self.scene:addChild(layout,1,key)
        LoadingLayer = layout
        local Layer = cc.CSLoader:createNode("res/yk/interface/loading.csb")
        local Action = cc.CSLoader:createTimeline("res/yk/interface/loading.csb")    --序列帧动画
        Layer:runAction(Action)
        --Action:setTimeSpeed(10/60)
        Action:gotoFrameAndPlay(0, true)
        LoadingLayer:addChild(Layer, 1)

        print("加载csb")
        print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
    end
end

 

posted @ 2017-11-15 17:14  冥府骑士格斯  阅读(654)  评论(0编辑  收藏  举报