1. Only cclayer and Its Derived classes have the touch function.
2. Enable touch
Settouchenable (true );
3. Set touch mode, single point, multi point (only supported by IOs)
Settouchmode (kcctouchesonebyone); // single point of touch
4. Four touch event functions to be overloaded
Bool cctouchbegan (cctouch * ptouch, ccevent * pevent); // returns false to indicate that the touch event will not be passed down.
Void cctouchmoved (cctouch * ptouch, ccevent * pevent); // move the event
Void cctouchended (cctouch * ptouch, ccevent * pevent); // end the event
Void cctouchcancelled (cctouch * ptouch, ccevent * pevent); // terminate the event
5. Obtain the coordinate point of the touch.
Ptouch-> getlocation ();
6. Get the moving relative displacement Delta
Ptouch-> getdelta ();
7. Determine whether the genie is being clicked, boundingbox (scaled size), and contentsize (actual size)
SPR-> boundingbox (). containspoint (ptouch-> getlocation () = true?
8. Set the touch priority and message swallowed-up
/* The Director obtains the touch event distributor */
Cctouchdispatcher * pdispatcher = ccdirector: shareddirector ()-> gettouchdispatcher ();
/*-1 indicates the priority of the message. A smaller value indicates a higher priority. False indicates that the message is not swallowed up. Setting true indicates that the message is swallowed up at the current layer and will not be passed down */
Pdispatcher-> addtargeteddelegate (this,-1, false );
Function prototype:
Void cctouchdispatcher: addtargeteddelegate (cctouchdelegate * pdelegate, int npriority, bool bswallowstouches );
Touch events and touch priorities in cocos2dx