[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.