Cocos2d-x version 2.1.3
Three steps required to complete a touch event
1. Override the registerWithTouchDispatcher event Method of the parent class.
VirtualvoidregisterWithTouchDispatcher ();
The content is, meaning to re-register in the director class
VoidHelloWorld: registerWithTouchDispatcher () {CCDirector: sharedDirector ()-> getTouchDispatcher ()-> addTargetedDelegate (this, 0, true );}
2. Allow touch. By default, CCLayer does not allow touch. Therefore, you must initialize the init method.
Write
SetTouchEnabled (true );
3. Override the touch method of the parent class
VirtualboolccTouchBegan (CCTouch * touch, CCEvent * event); virtualvoidccTouchMoved (CCTouch * touch, CCEvent * event); virtualvoidccTouchEnded (CCTouch * pTouch, CCEvent * pEvent );
In the first method, a return value is required to indicate whether to accept the touch event. If this parameter is set to true, the message event is not transmitted.