Search code examples
androidcocos2d-android

Cocos2D Touch HELP


I`m new to cocos2d library, I worked before with libgdx and pure openGL. How can I handle a touch event in Cocos2d for Android?


Solution

  • The 4 methods for handling touches on android are defined as follows:

    public boolean ccTouchesBegan(MotionEvent event);
    
    public boolean ccTouchesMoved(MotionEvent event);
    
    public boolean ccTouchesEnded(MotionEvent event);
    
    public boolean ccTouchesCancelled(MotionEvent event);
    

    These are the listeners you should use.

    And also add below line in constructor of your CCLayer class to enable touch event.

    this.setIsTouchEnabled(true);