展会信息港展会大全

Cocos2d-x中的多线程Demo
来源:互联网   发布日期:2015-09-27 15:26:23   浏览:1430次  

导读:.h文件 #ifndef __THREADDEMO_H_ #define __THREADDEMO_H_ #include cocos2d.h using namespace cocos2d; class ThreadDemo:public Layer{ public: CREATE_FUNC(ThreadDemo); virtual bool init(); static Scene *createScene(); void leftHand(); void righ...

.h文件

#ifndef __THREADDEMO_H_

#define __THREADDEMO_H_

#include "cocos2d.h"

using namespace cocos2d;

class ThreadDemo:public Layer{

public:

CREATE_FUNC(ThreadDemo);

virtual bool init();

static Scene *createScene();

void leftHand();

void rightHand();

};

#endif // !__THREADDEMO_H_

.cpp文件:

#include "ThreadDemo.h"

bool ThreadDemo::init(){

if (!Layer::init())

{

return false;

}

//创建、开启线程1

std::thread threah1 = std::thread(&ThreadDemo::leftHand,this);

threah1.detach();

//创建、开启线程2

std::thread thread2 = std::thread(&ThreadDemo::rightHand,this);

thread2.detach();

return true;

}

Scene *ThreadDemo::createScene(){

Scene *scene= Scene::create();

auto layer = ThreadDemo::create();

scene->addChild(layer);

return scene;

}

void ThreadDemo::leftHand(){

log("==========draw left start=============");

int num = 0;

while (num

这只是一个很简单的Demo,后期会有一个完善的,学习中。。。。。。

赞助本站

人工智能实验室
相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港