Cocos2d-x3.2 iOS下開啟多點觸控

來源:互聯網
上載者:User

Cocos2d-x3.2 iOS下開啟多點觸控

iOS下預設是不開啟多點觸控的,我們要想要使用需要做如下的內容:

iOS檔案夾下:AppController.mm


需要加一行代碼:

 //  只需要新增這樣一行代碼就可以使用多點觸控啦。    [eaglView setMultipleTouchEnabled:YES];        



具體位置見下面:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {        // Override point for customization after application launch.    // Add the view controller's view to the window and display.    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];    // Init the CCEAGLView    CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]                                     pixelFormat: kEAGLColorFormatRGBA8                                     depthFormat: GL_DEPTH24_STENCIL8_OES                              preserveBackbuffer: NO                                      sharegroup: nil                                   multiSampling: NO                                 numberOfSamples: 0];    // Use RootViewController manage CCEAGLView     _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];    _viewController.wantsFullScreenLayout = YES;    _viewController.view = eaglView;                //  只需要新增這樣一行代碼就可以使用多點觸控啦。    [eaglView setMultipleTouchEnabled:YES];            // Set RootViewController to window    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)    {        // warning: addSubView doesn't work on iOS6        [window addSubview: _viewController.view];    }    else    {        // use this method on ios6        [window setRootViewController:_viewController];    }    [window makeKeyAndVisible];    [[UIApplication sharedApplication] setStatusBarHidden:true];    // IMPORTANT: Setting the GLView should be done after creating the RootViewController    cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView);    cocos2d::Director::getInstance()->setOpenGLView(glview);    cocos2d::Application::getInstance()->run();    return YES;}

測試:

 auto listener1 = EventListenerTouchAllAtOnce::create();        listener1->setEnabled(true);        listener1->onTouchesBegan = [ = ](const std::vector& touches, Event* event)        {                        log("%lu",touches.size());                    };                _eventDispatcher->addEventListenerWithFixedPriority(listener1, 1);








聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.