有两种方式
1.重写 多点触摸
virtual void onTouchesBegan (const std::vector< cocos2d::Touch * > &touches,cocos2d::Event *unused_event);
2. 注册 单点触摸
auto dispatcher = Director::getInstance()->getEventDispatcher(); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan,this); listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved,this); listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded,this); listener->setSwallowTouches(true);//不向下传递触摸 dispatcher->addEventListenerWithSceneGraPHPriority(listener,this);
然后 重写
bool HelloWorld::onTouchBegan(Touch* touch,Event *event) void HelloWorld::onTouchEnded(cocos2d::Touch *touch,cocos2d::Event *unused_event)