zoukankan      html  css  js  c++  java
  • Cocos2d-x 文件路径下文件的读写

    1、推断决定路径下文件是否存在
    	std::string path=CCFileUtils::sharedFileUtils()->getWritablePath()+fileName;
     	bool isFileExist=CCFileUtils::sharedFileUtils()->isFileExist(path);

    2、假设你把Cocos2d-x 项目打包成安卓项目后,注意下路径的相关问题

    假设你在Cocos2d-x 的Resource 文件夹下有相关的配置文件比如说某.plist 文件,假设你想改动.plist 文件那么,应该把.plist 在程序首次执行的时候。写到安卓的Writable路径下

    //当玩家第一次进入游戏的时候
    void Loading::onFirstLoginWriteServerInfo()
    {
    	//获取可读写的路径和自己定义文件名称
    	std::string writabelPath=CCFileUtils::sharedFileUtils()->getWritablePath()+"test.plist";	
    	if (!CCFileUtils::sharedFileUtils()->isFileExist(writabelPath))
    	{		
    		//打开Resource路径下的.plist文件
    		CCDictionary *serverInfoDic=CCDictionary::createWithContentsOfFile("apps/test.plist");
    		if (serverInfoDic)
    		{			
    			//把test.plist 写到writablePath路径下
    			LOGAnroid("serverinfo.plist___writabelPath==%s",writabelPath.c_str());
    			serverInfoDic->writeToFile(writabelPath.c_str());
    		}
    	}
    	else
    	{
    		//非第一次登录游戏
    		LOGAnroid("NotFirstIn");
    	}
    }

    这样操作后。我们就对WritablePath路径下文件进行读写,假设不这种话,Resource路径下的文件在安卓下将移植到Assets 路径下。而Assets路径下的文件。好像是不能写,反正我是遇到了写不进去的情况~

  • 相关阅读:
    Docker底层技术了解(3)
    Docker整体结构了解(2)
    Docker简介(1)
    linux常用命令
    python反射
    flask线程隔离技术
    flask核心机制
    并发编程
    socket通信
    网络编程
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7390180.html
Copyright © 2011-2022 走看看