cocos2dx-2.x CCFileUtils文件管理类分析(1)

前端之家收集整理的这篇文章主要介绍了cocos2dx-2.x CCFileUtils文件管理类分析(1)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


  1. cocos2dx文件管理类是一个很重要的类,这里对这个类进行一下分析:
  2. CCFileUtils文件管理类的基类,不同平台下androidioswin32都有
  3. 继承于这个类的子类,如android
  4. class CC_DLL CCFileUtilsAndroid : public CCFileUtils
  5.  
  6. 1、单例类:
  7. static CCFileUtils* sharedFileUtils()
  8. 而实现却在CCFileUtilsAndroid.cpp文件中:并且创建的是各个平台下的子类实例
  9. CCFileUtils* CCFileUtils::sharedFileUtils()
  10. {
  11. if (s_sharedFileUtils == NULL)
  12. {
  13. s_sharedFileUtils = new CCFileUtilsAndroid();
  14. s_sharedFileUtils->init();
  15.  
  16. //获取apk包的路径,这里是java端设置的。
  17. std::string resourcePath = getApkPath();
  18.  
  19. // record the zip on the resource path
  20. // static ZipFile *s_pZipFile = NULL;
  21. // 因为android的很多资源是放在安装包里的assets文件里,
  22. //所以获取资源是需要从包里解压,这就用到了ZipFile类
  23. s_pZipFile = new ZipFile(resourcePath,"assets/");
  24. }
  25. return s_sharedFileUtils;
  26. }
  27.  
  28. 2、初始化:
  29. bool CCFileUtilsAndroid::init()
  30. {
  31. m_strDefaultResRootPath = "assets/"; //默认的资源路径,默认是安装包
  32. return CCFileUtils::init(); -->> 1
  33. }
  34. 1 -->>
  35. bool CCFileUtils::init()
  36. {
  37. //m_searchPathArray -- 资源搜索路径数组
  38. //m_searchResolutionsOrderArray -- 资源分辨率数组
  39. m_searchPathArray.push_back(m_strDefaultResRootPath);
  40. m_searchResolutionsOrderArray.push_back("");
  41. return true;
  42. }

猜你在找的Cocos2d-x相关文章