Cocos2d-x3.2 iOS下開啟多點觸控 – iPhone手機開發技術文章 iPhone軟體開發教學課程

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] 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);

發佈留言