cocos2dx文件管理类是一个很重要的类,这里对这个类进行一下分析:
CCFileUtils是文件管理类的基类,不同平台下android,ios,win32都有
继承于这个类的子类,如android
class CC_DLL CCFileUtilsAndroid : public CCFileUtils
1、单例类:
static CCFileUtils* sharedFileUtils()
而实现却在CCFileUtilsAndroid.cpp文件中:并且创建的是各个平台下的子类实例
CCFileUtils* CCFileUtils::sharedFileUtils()
{
if (s_sharedFileUtils == NULL)
{
s_sharedFileUtils = new CCFileUtilsAndroid();
s_sharedFileUtils->init();
//获取apk包的路径,这里是java端设置的。
std::string resourcePath = getApkPath();
// record the zip on the resource path
// static ZipFile *s_pZipFile = NULL;
// 因为android的很多资源是放在安装包里的assets文件里,
//所以获取资源是需要从包里解压,这就用到了ZipFile类
s_pZipFile = new ZipFile(resourcePath, "assets/");
}
return s_sharedFileUtils;
}
2、初始化:
bool CCFileUtilsAndroid::init()
{
m_strDefaultResRootPath = "assets/"; //默认的资源路径,默认是安装包
return CCFileUtils::init(); -->> 1
}
1 -->>
bool CCFileUtils::init()
{
//m_searchPathArray -- 资源搜索路径数组
//m_searchResolutionsOrderArray -- 资源分辨率数组
m_searchPathArray.push_back(m_strDefaultResRootPath);
m_searchResolutionsOrderArray.push_back("");
return true;
}