cocos2dx下CCLayer添加Touch事件

1.再init下 

this->setTouchEnabled(true);

2.重载方法virtual void registerWithTouchDispatcher(void); 

void PVPLogin::registerWithTouchDispatcher(void)

{

    CCDirector* pDirector = CCDirector::sharedDirector();

    pDirector->getTouchDispatcher()->addTargetedDelegate(this, -1, true);

}

3.重载相应的Touch方法 

virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);

virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);

virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);

virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);

原文地址:https://www.cnblogs.com/liuhaili/p/3083698.html