Cocos2d-x multi-touch Summary

Source: Internet
Author: User

[1]: What is the difference between this and spof?


1. Differences in usage.

In some cases, we need multi-touch to achieve better results, such as fruit cutting.


2. Differences from spof

[1]. The single-point monitoring class is CCtargetedTouchDelegate, while the multi-point monitoring class is CCtangardTouchDelegate.

[2]. You also need to register multi-touch. Here you may ask why single-touch is stored in the onEnter lifecycle function. Why do I write multiple points separately. This is because, if you put it in onEnter, it may crash.

[3]. In addition, the multi-touch function setTouchEnabled must be enabled.

[4]. ccTouchesBegan in multi-touch is not a boolean type.


[2]: Functions



Touch screen events:

1. register multi-touch

Virtual void registerWithTouchDispatcher (void );

2. The callback function returned when the user first touches the mobile phone screen

Virtual void ccTouchesBegan (CCSet * pTouches, CCEvent * pEvent );

3. Callback Function of the response when the user's finger slides on the screen of the mobile phone

Virtual void ccTouchesMoved (CCSet * pTouches, CCEvent * pEvent );

4. callback function returned when the user's finger leaves the mobile phone screen

Virtual void ccTouchesEnded (CCSet * pTouches, CCEvent * pEvent );


The CCTouch parameter is not used here, but their set.


CCtouch

1. getID () // obtain the subscript of the current contact (starting from 0)




[3]: Example


For ios platform, add

// Enable multi-touch .. disabled by default.
[_ GlView setMultipleTouchEnabled: YES];


This is not required for android, because it is enabled by default...

This problem once wasted a lot of time. Mark!



Touchsdemo. h


// Write the multi-touch callback function

Virtual void registerWithTouchDispatcher (void );

Virtual void ccTouchesBegan (CCSet * set, CCEvent * e );

Virtual void ccTouchesMoved (CCSet * set, CCEvent * e );

Virtual void ccTouchesEnded (CCSet * set, CCEvent * e );


Touchsdemo. cpp


// Enable multi-point

This-> setTouchEnabled (true );


2. register the listener


Void Touchsdemo: registerWithTouchDispatcher (void ){

// Register the listener

CCDirector: sharedDirector ()-> getTouchDispatcher ()-> addStandardDelegate (this, 0 );

}




3. Implement touch screen events


Void Touchsdemo: ccTouchesBegan (CCSet * set, CCEvent * e)

{

CCSetIterator iter = set-> begin ();

// The iter here is equivalent to the number allocated by the system,

// Set-> begin () to obtain the first number

// Set-> end () is the last one

For (; iter! = Set-> end (); iter ++ ){

// Here, it is a single point of processing, which can be understood as splitting multiple points into single points.

CCTouch * mytouch = (CCTouch *) (* iter );

CCPoint cp = mytouch-> getLocation ();

// Process each touch point

}

}




On the way to learning, I will share with you.


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.