您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Cocos2dx多点触摸实例

2025/12/12 20:59:30发布19次查看
bool mytouchevent2::init() { if (!layer::init()) { return false; } size visiblesize = director::getinstance()-getvisiblesize(); vec2 origin = director::getinstance()-getvisibleorigin(); label * text1 = label::create(, arial, 24); text1-setp
bool mytouchevent2::init()
{
if (!layer::init())
{
return false;
}
size visiblesize = director::getinstance()->getvisiblesize();
vec2 origin = director::getinstance()->getvisibleorigin();
label * text1 = label::create(, arial, 24);
text1->setposition(point(400, 280));
this->addchild(text1,1,1);
label * text2 = label::create(, arial, 24);
text2->setposition(point(400, 200));
this->addchild(text2,1,2);
label * text3 = label::create(, arial, 24);
text3->setposition(point(400, 100));
this->addchild(text3,1,3);
//创建多点触摸监听器
auto listener = eventlistenertouchallatonce::create();
//单击
listener->ontouchesbegan = [&](const std::vector& touchs, event* event)
{
auto text = (label *)this->getchildbytag(1);
int num = touchs.size();
text->setstring(value(num).asstring() + touches:);
};
       // 移动
listener->ontouchesmoved = [&](const std::vector& touchs, event* event)
{
auto text = (label *)this->getchildbytag(2);
int num = touchs.size();
std::string str = value(num).asstring() + touches:;
for (auto & touch:touchs)
{
auto location = touch->getlocation();
str += [touchid + value(touch->getid()).asstring() + ];
}
text->setstring(str);
};
       // 松开
listener->ontouchesended = [&](const std::vector& touchs, event* event)
{
auto text = (label*)this->getchildbytag(3);
int num = touchs.size();
text->setstring(value(num).asstring()+touches:);
};
//注册监听事件
_eventdispatcher->addeventlistenerwithscenegraphpriority(listener, this);
return true;
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product