开发者

How to use gesture recognizer in an OpenGLES application of iPhone?

开发者 https://www.devze.com 2023-01-18 08:19 出处:网络
While I know how to use gesture recognizer in a view-based application,bu开发者_如何学Pythont when I apply the same ideas in a OpenGLSE-based application:

While I know how to use gesture recognizer in a view-based application,bu开发者_如何学Pythont 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.


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");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消