在 Cocos2d-x 3.0 中检测触摸
在(HelloWorld.h)中编写代码{
cocos2d::EventListenerTouchAllAtOnce *Listner;
void onTouchesBegan(const std::vector<cocos2d::Touch *> &touches, cocos2d::Event *event);
void onTouchesMoved(const std::vector<cocos2d::Touch *> &touches, cocos2d::Event *event);
void onTouchesEnded(const std::vector<cocos2d::Touch *> &touches, cocos2d::Event *event);
}
在 init Method(HelloWorld.cpp) 中编写代码 {
Listner = EventListenerTouchAllAtOnce::create();
Listner->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this);
Listner->onTouchesMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this);
Listner->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(Listner, this);
}