4

While I know how to use gesture recognizer in a view-based application,but when I apply the same ideas in a OpenGLSE-based application: for example, I add a TapGestureRecognizer,and when I tap on the EAGLView,it crashes. So can anyone show me a standard usage of UITapGestureRecognizer in an OpenGLES-based application?

best wishes.

CarmeloS
  • 7,868
  • 8
  • 56
  • 103
  • I've not had direct experience with this, but have you tried adding it to the parent-view (like the window for example) instead? Not sure why, but it could require some layer functionality which is not implemented in the CAEAGLLayer class. – jhabbott Oct 03 '10 at 17:42
  • This is very strange, because I've had OpenGL ES hosting views responding to normal touch events without incident. Why would a gesture recognizer behave any differently? – Brad Larson Oct 04 '10 at 01:00
  • 1
    I've used tap gesture recognisers for basic UIViews and EAGLViews and they work exactly the same. You probably have a problem elsewhere. What's your crash log say? – No one in particular Oct 05 '10 at 01:06

1 Answers1

4

Here some sample code from one of my opengles games with gesture support. (Doesn't crash and hope it helps)

- (void)viewDidLoad {
    [super viewDidLoad];

    CGRect  rect = [[UIScreen mainScreen] bounds];
    rect.size.height = 320;
    rect.size.width = 480;
    rect.origin.x = 0;
    rect.origin.y = 0;

    glView = [[EAGLView alloc] initWithFrame:rect pixelFormat:GL_RGB565_OES depthFormat:GL_DEPTH_COMPONENT16_OES preserveBackbuffer:NO];
    [self.view addSubview: glView];

    [glView addSubview: minimapView];

    if(!shell->InitApplication())
        printf("InitApplication error\n");

    [NSTimer scheduledTimerWithTimeInterval:(1.0 / kFPS) target:self selector:@selector(update) userInfo:nil repeats:YES];

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(Panned:)];
    [glView addGestureRecognizer:[pan autorelease]];    

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Tapped:)];
    [glView addGestureRecognizer:[tap autorelease]];    

    UITapGestureRecognizer *dbltap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DoubleTapped:)];
    [dbltap setNumberOfTapsRequired:2];
    [glView addGestureRecognizer:[dbltap autorelease]];

    UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressed:)];
    [glView addGestureRecognizer:[longpress autorelease]];      
}

And the selector function

- (void) LongPressed:(UILongPressGestureRecognizer*)sender{
    NSLog(@"Long Pressed");
}
Tyler Zale
  • 634
  • 1
  • 7
  • 23