您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

23 行
632 B

  1. -- 全局缓存,会在退出时自动销毁
  2. local UICache = cc.RefObjectCache:create();
  3. -- 从缓存中加载ui
  4. function loadUIFromCache(filename)
  5. local ui = UICache:pop(filename);
  6. if ui == nil then
  7. print("加载ui:" , filename);
  8. ui = loadUI(filename);
  9. local function onNodeEvent(node , eventType)
  10. if eventType == cc.NodeEvent.OnEnter then
  11. elseif eventType == cc.NodeEvent.OnExit then
  12. print("回收ui:" , filename);
  13. ui:removeAllChildrenTouchEvent()
  14. UICache:push(filename , ui);
  15. end
  16. end
  17. ui:addNodeEventListener(onNodeEvent)
  18. else
  19. print("从缓存中获取ui:" , filename);
  20. end
  21. return ui;
  22. end