[8] coco2d-x event handling mechanism

Source: Internet
Author: User

I. Touch Screen events

In Coco2d-x, inheriting the touch screen proxy protocol CCTouchDelegate can detect touch screen events and call callback functions. Is the CCTouchDelegate class inheritance relationship diagram:

CCStandardTouchDelegate is a standard example for obtaining multi-point touch. CCTargeteTouchDelegate does not need to process the set of touch points. It returns a single point. However, CCTargeteTouchDelegate does not shield the multi-point touch. Instead, it splits the multi-point into a single point and transmits it at the same time.

1: Contact Type CCTouch

CCTouch encapsulates the information of the touch point. It includes the horizontal and vertical coordinates of the touch point and the touch point id. CCTouch is passed as a parameter in the function.

Get coordinate value:

CCPoint point = touch-> getLocationInView ();

Point = CCDirector-> shareddire()-> converTOGL (point );

CCouch is passed in the touch function. The touch function is as follows:

 

To use a touch, you must first add a touch for the inherited CCTouchDeleagte class

Add a single touch: pDirector-> getTouchDispatcher ()-> addTargetedDelegate (this, 0, true );

Add multiple touch points: PDirector-> getTouchDispatcher ()-> addStandardTouchDelegate (this, 0 );

The difference is that CCTouch is transmitted in a single touch, and the coordinates of the touch points can be obtained directly. 2. In multi-touch mode, the parameter passed is CCSet *>

PtTemp. y = pAccelerationValue. y * 9.81f;

 

 

 

 

 

 

 

Related Article

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.