You need to register with CCTouchDispatcher to get the touch:
Write this in your init()
method to get the finishing touches:
CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this, 0);
In addition, I recommend that you receive the touch event using the touch delegate target methods:
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);
For these methods to be called, you need to register with the touch manager a little differently:
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
EDIT
In the new cocos version, CCTouchDispatcher
is located in CCDirector
:
It should look something like this:
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
source share