zoukankan      html  css  js  c++  java
  • 加载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
  • 相关阅读:
    C++ Builder XE2随意学习 (12) > DevExpress Dock拖动框架实现
    C++ Builder XE2随意学习 (14) > 窗口透明处理
    C++ Builder XE2随意学习(9) > 安装实录
    C++ Builder XE2随意学习 (13) > Gdiplus
    C++ Builder XE2随意学习 (10) > AlphaControls控件使用初探
    ASP.NET 4.0 视频教程
    C++ Builder XE2随意学习 (11) > DevExpress Ribbon界面效果
    C++ Builder XE2随意学习 (7) > RAD Studio XE2 – Setting it up for a Mac
    C++ Builder XE2随意学习(8) > 快速入门教程
    jQuery实现倒计时效果
  • 原文地址:https://www.cnblogs.com/mingfuqishi/p/7839922.html
Copyright © 2011-2022 走看看