If the non-set layer class and its subclass want to use touch, the corresponding proxy should be inherited,
For example, in the TouchesTest folder of the test project, the class is inherited from CCSprite.
Instead of the Set layer class, it uses the proxy CCTargetedTouchDelegate
Unlike the set layer, the registration and logout of the touch proxy must be performed in OnEnter () and OnExit ().
Do not set the layer class and its subclass to use touch:
1. inherit the corresponding proxy. For example, in the TouchesTest folder of the test project, the Paddle. h inherits the proxy CCTargetedTouchDelegate.
2. Register and deregister the touch proxy in OnEnter () and OnExit ()
3. methods required for implementation: bool ccTouchBegan (CCTouch * touch, CCEvent * event) is required
For example, in the TouchesTest folder of the test project
virtual void onEnter(); virtual void onExit(); virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
void Paddle::onEnter(){ CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); CCSprite::onEnter();}void Paddle::onExit(){ CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->removeDelegate(this); CCSprite::onExit();}