zoukankan      html  css  js  c++  java
  • cocos2dx android lua文件设置问题

    cocos2d-x版本: cocos2d-2.1rc0-x-2.1.2

    通常我们在文件AppDelegate.cpp的applicationDidFinishLaunching()函数中设置lua代码路径方式如下:

    1  std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(“programe/xxx.lua");
    2  pEngine->addSearchPath( path.substr( 0, path.find_last_of( "/" ) ).c_str() );
    3  pEngine->executeScriptFile( path.c_str() );

    在pc和ios上面能够运行良好,但是android上面就不行了,一直提示错误:

     get data from file(program/xxx.lua) failed 

    解决办法:

     1 const char* luaFile = "program/main.lua";
     2 #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
     3     CCString* pstrFileContent = CCString::createWithContentsOfFile(luaFile);
     4     if ( pstrFileContent ) {
     5         std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(luaFile);
     6         CCLog("path = %s", path.c_str());
     7         std::string subPath = path.substr(0, path.find_last_of("/"));
     8         CCLog("sub path = %s", subPath.c_str());
     9 
    10         pEngine->addSearchPath(subPath.c_str());
    11 
    12         std::vector<std::string> searchPaths = CCFileUtils::sharedFileUtils()->getSearchPaths();
    13         searchPaths.insert(searchPaths.begin(), subPath);
    14         CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
    15 
    16         pEngine->executeString(pstrFileContent->getCString());
    17     }
    18 #else        
    19     std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(luaFile);
    20     pEngine->addSearchPath( path.substr( 0, path.find_last_of( "/" ) ).c_str() );
    21     pEngine->executeScriptFile( path.c_str() );
    22 #endif
  • 相关阅读:
    Keras -- 词向量 CNN
    KUDU实时分析
    Keras
    Kalfka
    Linux云
    管理KUDU
    列存储与行存储
    算法笔记 第5章 入门篇(3) --数学问题 学习笔记
    算法笔记 上机训练实战指南 第4章 入门篇(2) --算法初步 4.6two pointers 学习笔记
    算法笔记 上机训练实战指南 第4章 入门篇(2) --算法初步 4.4贪心 学习笔记
  • 原文地址:https://www.cnblogs.com/520zijuan/p/3573223.html
Copyright © 2011-2022 走看看