
{
if (!Layer::init())
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
/创建3个文本标签
Label * text1 = Label::create("","Arial",24);
text1->setposition(Point(400,280));
this->addChild(text1,1,1);
Label * text2 = Label::create("",24);
text2->setposition(Point(400,200));
this->addChild(text2,2);
Label * text3 = Label::create("",24);
text3->setposition(Point(400,100));
this->addChild(text3,3);
//创建多点触摸监听器
auto Listener = EventListenertouchAllAtOnce::create();
//单击
Listener->ontouchesBegan = [&](const std::vector<touch*>& touchs,Event* event)
{
auto text = (Label *)this->getChildByTag(1);
int num = touchs.size();
text->setString(Value(num).asstring() + "touches:");
};
// 移动
Listener->ontouchesMoved = [&](const std::vector<touch*>& 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<touch*>& 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; } 总结以上是内存溢出为你收集整理的Cocos2dx多点触摸实例全部内容,希望文章能够帮你解决Cocos2dx多点触摸实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)