cocos2d-x线程安全(三)主线程更新UI
发布时间:2020-12-14 18:54:24 所属栏目:百科 来源:网络整理
导读:xxx.h文件: void threadA(); xxx.cpp文件: //1.新建线程A std ::thread t1( Login ::threadA ,this); //取Login的地址 t1 . detach(); //设置主线程和子线程互不影响 void Login ::threadA(){ // C++的匿名函数框: [, this ] {} Director ::getInstance (
xxx.h文件: void threadA();
xxx.cpp文件: //1.新建线程A
std::thread t1(&Login::threadA,this);//取Login的地址
t1.detach();//设置主线程和子线程互不影响
void Login::threadA()
{
//C++的匿名函数框: [&,this] {}
Director::getInstance()->getScheduler()->performFunctionInCocosThread([&,this] {
//在本子线程中创建一个精灵(不能直接在非UI线程(主线程)操作),直接添加时失败的。
auto sprite1 = Sprite::create("niu/fonts_006_10000.png");
addChild(sprite1);
Size size = Director::getInstance()->getWinSize();
sprite1->setPosition(size / 2);//居中
});
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |