_Cache

创建缓存,加载资源的时候使用,减少IO使用次数 全部展开

构造方法展开

  • + function _Cache( )
    • 示例

       cache = _Cache.new( )

公共方法展开

  • + function addCache(resname: String, object)

    添加资源对象到缓存。

    • 参数
    • resname :资源名。
    • object:Image, Skeleton, Mesh, Animation, Particle, GraphicsData, ,_GraphicsEvent对象。

    • 示例

      cache:addCache("girl.skl," skl)
  • + function beginRecord( )

    开始记录缓存。

  • + function clearCaches( )

    清除缓存中的资源。

  • + function delCache(resname: String)

    通过资源名删除一条缓存。

    • 参数
    • resname: String 资源名。
  • + function endRecord()

    停止记录缓存。

  • + function getCache(resname: String)

    获取缓存里面的资源对象。

    • 参数
    • resname : 资源名。
    • 示例

       san = cache:getCache('girl.san')
  • + function getCacheCount( )

    获取缓存的数量。

    • 示例

       count = cache:getCacheCount()
  • + function getCaches( )

    获取缓存里面的资源。

    • 示例

        for i, v in ipairs(cache:getCaches()) do
      print(v.resname,v.object)
      end

代码示例

    _dofile('cameracontrol.lua')
    _sys:addPath('res')

    function loadPlayer(c)
    local p = {}
    p.skl = _Skeleton.new('char_rose.skl')
    p.san = p.skl:addAnima('char_rose_skill_01.san')
    p.skn = _Mesh.new('char_rose.skn')
    p.skn:attachSkeleton(p.skl)
    if c then
    p.san:triggerEvents()
    else
    p.san.loop = true
    p.san:play()
    end
    return p
    end

    cache = _Cache.new()
    cache:beginRecord()
    loadPlayer(true)
    cache:endRecord()
    _gc()

    --[[
    local res = cache:getCaches()
    for i, v in ipairs(res) do
    print('### Caching', v.resname, v.object)
    end
    --]]

    _debug:ioReadMonitor(_true, 1000)
    _debug.monitor = true

    _app:onKeyDown(function(key)
    if key == _System.KeySpace then
    player = nil
    _gc()
    player = loadPlayer()
    elseif key == _System.KeyReturn then
    player = nil
    cache = nil
    _gc()
    end
    end)

    _app:onIdle(function()
    if player then
    player.skn:drawMesh()
    end
    end)
问题反馈(登录才可以发表哦!)