• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cocos2dxandroidlua文件设置问题

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++实现对lua访问的封装发布时间:2022-07-22
下一篇:
lua-table的集合使用发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap