Touch events and touch priorities in cocos2dx

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.