You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
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