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;