Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3953198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:56:46+00:00 2026-05-20T01:56:46+00:00

Has anyone managed to get the gesture recognition working in cocos-2d? I have read

  • 0

Has anyone managed to get the gesture recognition working in cocos-2d?

I have read a post here that claimed to have achieved it, here: http://www.cocos2d-iphone.org/forum/topic/8929

I patched from the git hub here: https://github.com/xemus/cocos2d-GestureRecognizers/blob/master/README

I made a subclass of CCSprite (which is a subclass of CCNode):

-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect {
if( (self=[super initWithTexture:texture rect:rect]) )
{
    CCGestureRecognizer* recognizer;
    recognizer = [CCGestureRecognizer 
        CCRecognizerWithRecognizerTargetAction:[[[UITapGestureRecognizer alloc]init] autorelease] 
                  target:self 
                  action:@selector(tap:node:)];
    [self addGestureRecognizer:recognizer];
}
return self;
}

Delegate method:

- (void) swipe:(UIGestureRecognizer*)recognizer node:(CCNode*)node
{
NSLog(@" I never get called :( ");
}

My tap event never gets called.

Has anyone got this working? How difficult is it to do gesture recognition manually for swipe detection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:56:47+00:00Added an answer on May 20, 2026 at 1:56 am

    You need to attach the gesture recognizer to something “up the chain”. Don’t attach them to the individual nodes; attach them to the UIView (i.e., [[CCDirector sharedDirector] openGLView]).

    Here’s what I did:

    - (UIPanGestureRecognizer *)watchForPan:(SEL)selector number:(int)tapsRequired {
        UIPanGestureRecognizer *recognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:selector] autorelease];
        recognizer.minimumNumberOfTouches = tapsRequired;
        [[[CCDirector sharedDirector] openGLView] addGestureRecognizer:recognizer];
        return recognizer;
    }
    
    - (void)unwatch:(UIGestureRecognizer *)gr {
        [[[CCDirector sharedDirector] openGLView] removeGestureRecognizer:gr];
    }
    

    This particular code is used in a superclass for scene controllers, so the target for the selector is hard-coded to “self”, but you could easily abstract that to a passed-in object. Also, you could extrapolate the above to easily create gesture recognizers for taps, pinches, etc.

    In the subclass for the controller, then, I just do this:

    - (MyController *)init {
        if ((self = [super init])) {
            [self watchForPan:@selector(panning:) number:1];
        }
        return self;
    }
    
    - (void)panning:(UIPanGestureRecognizer *)recognizer {
    
        CGPoint p;
        CGPoint v;
    
        switch( recognizer.state ) {
            case UIGestureRecognizerStatePossible:
            case UIGestureRecognizerStateBegan:
                p = [recognizer locationInView:[CCDirector sharedDirector].openGLView];
                (do something when the pan begins)
                break;
            case UIGestureRecognizerStateChanged:
                p = [recognizer locationInView:[CCDirector sharedDirector].openGLView];
                (do something while the pan is in progress)
                break;
            case UIGestureRecognizerStateFailed:
                break;
            case UIGestureRecognizerStateEnded:
            case UIGestureRecognizerStateCancelled:
                (do something when the pan ends)
                (the below gets the velocity; good for letting player "fling" things)
                v = [recognizer velocityInView:[CCDirector sharedDirector].openGLView];
                break;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone managed to get subsonic or a variant working on Windows Mobile? We
Has anyone managed to get the transfer mechanism working with FILESTREAM columns? My code
Has anyone managed to get this to work? Closest I have found is a
Has anyone managed to get OpenGL ES 2.0 working in a live wallpaper? I
Has anyone managed to get a custom IMessageInterpolator working to enable customisation of error
Has anyone managed to get Ninject working in Metro Style app using the Windows
Has anyone managed to get administration rights through the UAC without restarting the application
Has anyone managed to use ItemizedOverlays in Android Beta 0.9? I can't get it
Has anyone managed to get a DBLookupComboBox to work with a DBCtrlGrid ? A
Has anyone managed to use core-plot from wax? I have been trying recently, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.