加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 20:45:15 所属栏目:百科 来源:网络整理
导读:cocos2dx文件管理类是一个很重要的类,这里对这个类进行一下分析:CCFileUtils是文件管理类的基类,不同平台下android,ios,win32都有继承于这个类的子类,如androidclass CC_DLL CCFileUtilsAndroid : public CCFileUtils1、单例类:static CCFileUtils* s


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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读