单点触摸:
auto label = LabelTTF::create("Label","CourIEr",30); label->setposition(visibleSize / 2); this->addChild(label); auto Listener = EventListenertouchOneByOne::create(); /*创建事件侦听*/ Listener->ontouchBegan = [](touch *touch,Event* event){ /*开始点击触发回调函数*/ if (event->getCurrentTarget()->getBoundingBox().containsPoint( /*触摸点是否在目标范围*/ touch->getLocation())){ cclOG("OK"); } return false; /*事件是否传递 false不传递,true传递*/ }; /*在场景中注册事件*/ Director::getInstance()->getEventdispatcher()-> addEventListenerWithSceneGraPHPriority(Listener,label);
多点触摸:
auto Listener = EventListenertouchAllAtOnce::create(); Listener->ontouchesBegan = [](std::vector<touch*> touchs,Event* event){ cclOG("touchs Began!"); }; Listener->ontouchesMoved = [](std::vector<touch*> touchs,Event* event){ cclOG("touchs Move: %d",touchs.size()); }; Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,this);总结
以上是内存溢出为你收集整理的cocos2dx 触摸事件全部内容,希望文章能够帮你解决cocos2dx 触摸事件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)