How to Enable Multi-Touch
The Multi-touch features have been available on both iOS & Android since the first version of cocos2d-x. In iOS, Apple turns multi-touch off by default. Use the API to enable it manually.
iOS
Please refer to cocos2d-x/tests/cpp-tests/proj.ios/Classes/testsAppDelegate.mm
, line 60:
1 | [eaglView setMultipleTouchEnabled:YES]; |
You can modify this file MyGame/proj.ios/AppController.mm
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | - application:application didFinishLaunchingWithOptions:launchOptions { // Override point for customization after application launch. // Add the view controller’s view to the window and display. window = initWithFrame: bounds]]; EAGLView \**glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGBA8 depthFormat: GL\_DEPTH\_COMPONENT16\_OES preserveBackbuffer: NO sharegroup: nil multiSampling: NO numberOfSamples: 0 ]; [_glView setMultipleTouchEnabled:YES]; // enable multi-touch here![]() It’s at about line 37 // … return YES; } |
Apple official document about setMultipleTouchEnabled
.
Android
On android, the multi-touch is open by default. You don’t need to open anything before get the touch coordinates in void MyLayer::ccTouchesBegan/Moved/Ended
Other platforms
People usually debug cocos2d-x games on windows desktop system. But sadly, there’s no multi-touch support on windows. You had to connect your mobile phones and test multi-touch feature on them.
Multi-touch Test Case
We added a test case for multi-touch since v2.0. After launching TestCpp, you can enter this test case from “MultiTouchTest”. There is a video.