1. 程式人生 > >cocos2d-x 3.16 ios開啟多點觸控

cocos2d-x 3.16 ios開啟多點觸控

今天遇到坑,就是在實現多點觸控時不放幾個手指到螢幕上,獲取的觸控點得個數都是1。

最終解決方案:

找到iOS檔案RootViewController.mm,新增
[eaglView setMultipleTouchEnabled:YES]

全部程式碼如下:

#import "RootViewController.h"
#import "cocos2d.h"
#import "platform/ios/CCEAGLView-ios.h"


@implementation RootViewController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/
// Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { // Initialize the CCEAGLView CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [UIScreen mainScreen].bounds pixelFormat: (__bridge NSString *)cocos2d::GLViewImpl::_pixelFormat depthFormat: cocos2d::GLViewImpl::_depthFormat preserveBackbuffer: NO
sharegroup: nil multiSampling: NO numberOfSamples: 0 ]; //將NO改為YES就可以使用多點觸控啦! [eaglView setMultipleTouchEnabled:YES]; // Set EAGLView as view of RootViewController self
.view = eaglView; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead #ifdef __IPHONE_6_0 - (NSUInteger) supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAllButUpsideDown; } #endif - (BOOL) shouldAutorotate { return YES; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; auto glview = cocos2d::Director::getInstance()->getOpenGLView(); if (glview) { CCEAGLView *eaglview = (__bridge CCEAGLView *)glview->getEAGLView(); if (eaglview) { CGSize s = CGSizeMake([eaglview getWidth], [eaglview getHeight]); cocos2d::Application::getInstance()->applicationScreenSizeChanged((int) s.width, (int) s.height); } } } //fix not hide status on ios7 - (BOOL)prefersStatusBarHidden { return YES; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } @end