I'm using cocos2d-x v3.3rc0
I'm trying to handle multi touch, but I only receive only one touch.
It's behavior is similar with single touch, not multitouch. onTouchesBegan only called once when I touch more than 1 finger.
Hope someone can help me solve this out.
Here is my code to enable multi touch
ControlLayer.h
#include "cocos2d.h"
class ControlLayer : public cocos2d::Layer{
public:
static ControlLayer* create();
virtual bool init();
void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *unused_event);
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *unused_event);
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *unused_event);
};
ControlLayer.cpp
bool ControlLayer::init(){
if (!Layer::init()){
return false;
}
auto touchListener = EventListenerTouchAllAtOnce::create();
touchListener->onTouchesBegan = CC_CALLBACK_2(ControlLayer::onTouchesBegan, this);
touchListener->onTouchesMoved = CC_CALLBACK_2(ControlLayer::onTouchesMoved, this);
touchListener->onTouchesEnded = CC_CALLBACK_2(ControlLayer::onTouchesEnded, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this);
return true;
}
void ControlLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event){
CCLOG("onTouchesBegan[%lu]", touches.size());
}
void ControlLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event){
CCLOG("onTouchesMoved[%lu]", touches.size());
}
void ControlLayer::onTouchesEnded(const std::vector<Touch*>& touches, Event *unused_event){
}