cocos2d的多点触控

    技术2022-05-20  59

    1:

    StandardTouchDelegate协议,

     

    @protocol CCStandardTouchDelegate <NSObject>

    @optional

    - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

    - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

    - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

    - (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent*)event;

    @end

    此协议用于实现多点触控,原理是EAGLView继承自UIView,继承了touch的四个方法,而cocos2d在director绑定了EAGLView:

    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]

             pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8

           depthFormat:0 // GL_DEPTH_COMPONENT16_OES

    ];

    // attach the openglView to the director

    [director setOpenGLView:glView];

     

    2:接受多个触控点,必须在入口处调用

    [viewController.view setMultipleTouchEnabled:YES];

         否则只能接受单点。

         layer在init时isTouchEnabled必须设置为yes,此方法会调用registerWithTouchDispatcher,将layer注册到TouchDelegate。

    3:mac机上实验多点触控,只能测试到两个点:

    option + 点击

    option + shift 实现平移

     


    最新回复(0)