iDev/Cocos2D

cocos2d에 UIGesture 추가하기

KraZYeom 2014. 5. 22. 08:17
반응형

RayWenderlich의 캔디 크러시 따라 만들기를 SpriteKit에서 cocos2d v3로 포팅을 하고 있는데 UIGesture 부분이 나와서 삽질 아닌 삽질을 공유한다. 


딱 한가지만 알아두면 된다. cocos2d에서 RootViewController(UIViewController)는 CCDirector이다. 


- (void)showGameOver {

  self.gameOverPanel.visible = YES;

  self.myscene.userInteractionEnabled = NO;

  

  self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideGameOver)];

  

  UIViewController *viewController = (UIViewController *)[CCDirector sharedDirector];

  [viewController.view addGestureRecognizer:self.tapGestureRecognizer];

}


- (void)hideGameOver {

  UIViewController *viewController = (UIViewController *)[CCDirector sharedDirector];


  [viewController.view removeGestureRecognizer:self.tapGestureRecognizer];

  self.tapGestureRecognizer = nil;

  

  self.gameOverPanel.visible = NO;

  self.myscene.userInteractionEnabled = YES;

  

  [self beginGame];

}


반응형