应用中使用的滑动手势

时间:2012-10-12 09:12:08

标签: cocos2d-iphone

我有关于使用滑动手势的问题。

问题是我想要在左右点击改变方向的同时左右滑动。

我可以在这种情况下使用CCTouch方法吗?如果是,那我该怎么用?还有另一种方法吗?

1 个答案:

答案 0 :(得分:0)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{
  ...
  ...
     [self createSwipeRecognizerView];

     return YES;

}



-(void) createSwipeRecognizerView {
    //NSLog(@"Creating Swipe Recognizer");

    UIGestureRecognizer *recognizer;
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(screenDidswipe)];
    // swipeRightOnTable is the callback method in my case

    swipeRecognizer = (UISwipeGestureRecognizer *)recognizer;
    // select swipe direction
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionUp;

    [self.navController.view addGestureRecognizer:recognizer];
    recognizer.delegate = self;
    [recognizer release];
}

    -(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
    {
        if([[MyGame sharedGameObject].layer isKindOfClass:[MyGameScreen class]])
            return YES;
        return NO;
    }

    -(void) screenDidswipe 
    {
        MyGame *sGame = [MyGame sharedGameObject];
        if([sGame.layer isKindOfClass:[MyGameScreen class]])
        {
            [(MyGameScreen*)(sGame.layer) screenDidswipe];
        }
    }