//1、
//cocos 程序开始运行时执行的函数
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
auto director = Director::getInstance();
director->setProjection(Director::Projection::_2D); // turn on display FPS
director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / );
director->startAnimation(); // register lua engine
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
lua_State* L = engine->getLuaStack()->getLuaState();
lua_module_register(L); // If you want to use Quick-Cocos2dx-Community, please uncomment below code
quick_module_register(L); LuaStack* stack = engine->getLuaStack();
// stack->setXXTEAKeyAndSign("2dxLua", "XXTEA"); //主要来看下这部分:
StartupCall *call = StartupCall::create(this);
call->startup(); return true;
} //2、
void StartupCall::startup()
{
auto engine = LuaEngine::getInstance();
auto stack = engine->getLuaStack(); const ProjectConfig &project = _app->_project; // set search path
// 设置工程搜索路径
string path = FileUtils::getInstance()->fullPathForFilename(project.getScriptFileRealPath().c_str());
size_t pos;
while ((pos = path.find_first_of("\\")) != std::string::npos)
{
path.replace(pos, , "/");
}
size_t p = path.find_last_of("/");
string workdir;
if (p != path.npos)
{
workdir = path.substr(, p);
// Lua 代码文件的搜索需要包含src
stack->addSearchPath(workdir.c_str());
// cc.FileUtils的文件搜索去掉src目录
size_t p = workdir.find_last_of("/");
workdir = path.substr(, p);
FileUtils::getInstance()->addSearchPath(workdir);
} // load framework
if (project.isLoadPrecompiledFramework())
{
const string precompiledFrameworkPath = project.getPrecompiledFrameworkPath();
stack->loadChunksFromZIP(precompiledFrameworkPath.c_str());
} // load script
string env = "__LUA_STARTUP_FILE__=\"";
env.append(path);
env.append("\"");
engine->executeString(env.c_str()); CCLOG("------------------------------------------------");
CCLOG("LOAD LUA FILE: %s", path.c_str());
CCLOG("------------------------------------------------");
engine->executeScriptFile(path.c_str()); // track start event
trackLaunchEvent();
} //跟踪启动事件
void StartupCall::trackEvent(const char *eventName)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
const char *platform = "win";
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
const char *platform = "mac";
#else
const char *platform = "UNKNOWN";
#endif HTTPRequest *request = HTTPRequest::createWithUrl(NULL,
"http://www.google-analytics.com/collect",
kCCHTTPRequestMethodPOST);
request->addPOSTValue("v", "");
request->addPOSTValue("tid", "UA-84326395-1");
request->addPOSTValue("cid", Native::getOpenUDID().c_str());
request->addPOSTValue("t", "event"); request->addPOSTValue("an", "player");
request->addPOSTValue("av", cocos2dVersion()); request->addPOSTValue("ec", platform);
request->addPOSTValue("ea", eventName); request->start();
}

最新文章

  1. Leetcode:378. Kth Smallest Element in a Sorted Matrix
  2. Quickling技术
  3. MFC中挂起线程和恢复线程
  4. VS2010开发环境最佳字体及配色[转]
  5. check、continue、exit的区别
  6. 使用Echarts的五个步骤
  7. MySQL高可用基础之keepalived+双主复制【转】
  8. Firemonkey绑定对象列表
  9. OC实现带弹跳动画按钮的界面控制器view
  10. 100-days: twenty-one
  11. springcloud学习总结
  12. 深入理解 Java try-with-resource 语法糖
  13. 解决Linux 下 root用户删除文件提示:Operation not permitted
  14. JDK安装教程(Windows7 x64)
  15. CSS3 transform变形(2D转换)
  16. linux cp 和scp详解
  17. IEDriver executable needs to be available in the path
  18. Python入门-模块1(模块导入与time模块)
  19. 洛谷P1038神经网络
  20. HBase二级索引方案总结

热门文章

  1. 【转载】C#中AddRange方法往ArrayList集合末尾添加另一个集合
  2. EntityFramework DBContext 类动态控制 数据库连接(支持Oracle,SQL server)
  3. uni-app学习(二)
  4. 2007英语CET6四6级资料六级大学单词
  5. vue 子组件 $emit方法 调用父组件方法
  6. Linux 环境变量配置错误,导致所有命令找不到
  7. css透明度、毛玻璃效果
  8. 运维基础——Zabbix:Lack of free swap space on Zabbix server
  9. 【转】大众点评CAT开源监控系统剖析
  10. Find the median(2019年牛客多校第七场E题+左闭右开线段树)