在cocos2d-x 3.0中,我们通常使用EventListenerTouchAllAtOnce这种方式来监听多点触控
例如
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = CC_CALLBACK_2(PlayMusic::onTouchesBegan, this);
listener->onTouchesMoved = CC_CALLBACK_2(PlayMusic::onTouchesMoved, this);
listener->onTouchesEnded = CC_CALLBACK_2(PlayMusic::onTouchesEnded, this);
listener->onTouchesCancelled = CC_CALLBACK_2(PlayMusic::onTouchesCancelled, this);
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
四个回调函数分别对应:
1.手指按下
2.手指划动
3.手指松开
4.意外中断触摸(弹窗之类的)
四个函数的原型为:
void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
void