Attach TouchesBegan to CCLayer without subclassing

Hi,

I actually need to wire up event handler to CCLayer object so that it can handle the touch events. One way to do is to subclass the CCLayer Class. But how we can do this without subclassing it in c++?

You should implement the CCTargetedTouchDelegate.

Add this to onEnter():
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);

Add this onExit():
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);

Thanks for reply. But “getTouchDispatcher” is not available for c*+ in Windows Phone. Is there any alternative for “getTouchDispatcher” in c*+ version?