|
- -- 全局缓存,会在退出时自动销毁
- local UICache = cc.RefObjectCache:create();
-
- -- 从缓存中加载ui
- function loadUIFromCache(filename)
- local ui = UICache:pop(filename);
- if ui == nil then
- print("加载ui:" , filename);
- ui = loadUI(filename);
- local function onNodeEvent(node , eventType)
- if eventType == cc.NodeEvent.OnEnter then
- elseif eventType == cc.NodeEvent.OnExit then
- print("回收ui:" , filename);
- ui:removeAllChildrenTouchEvent()
- UICache:push(filename , ui);
- end
- end
- ui:addNodeEventListener(onNodeEvent)
- else
- print("从缓存中获取ui:" , filename);
- end
- return ui;
- end
|