0

我正在研究基于GLKViewController的游戏,该游戏将水龙头和滑动解释为游戏控制。我想通过让第一个玩家在屏幕左侧轻点或滑动,并让第二个玩家在屏幕右侧轻击或滑动来支持双人模式。在一个完美的世界里,即使滑动是sl and的,并且通过屏幕的中心线(用滑动的起始点来确定哪个玩家获得输入),我还是希望手势识别器能够工作。iPad:屏幕左侧/右侧的手势识别器

什么是最好的实施方式?我可以在屏幕左半边放置一个手势识别器,另一个放在屏幕右侧?即使双方在同一时间被轻拍/快速扫描,两个单独的识别器是否能够正常工作?或者我应该创建一个全屏幕识别器,并且完全依靠我自己来解析滑动和轻敲?我没有手势识别器的经验,所以我不知道最好的方法是什么,或者当你同时刷多个手势时它们的工作效果如何。

回答

0

我最终将两个UIViews叠加在我的GLKView的顶部,一个在屏幕的左侧,另一个在右侧。每个视图有一个UIPanGestureRecognizer和一个UILongPressGestureRecognizer(长按识别器基本上是一个更灵活的敲击 - 我需要用它来拒绝某些手势同时被解释为平移和敲击)。这工作很有成效。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Add tap and pan gesture recognizers to handle game input. 
    { 
     UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSidePan:)]; 
     panRecognizer.delegate = self; 
     [self.leftSideView addGestureRecognizer:panRecognizer]; 

     UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSideLongPress:)]; 
     longPressRecognizer.delegate = self; 
     longPressRecognizer.minimumPressDuration = 0.0; 
     [self.leftSideView addGestureRecognizer:longPressRecognizer]; 
    } 
    { 
     UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSidePan:)]; 
     panRecognizer.delegate = self; 
     [self.rightSideView addGestureRecognizer:panRecognizer]; 

     UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSideLongPress:)]; 
     longPressRecognizer.delegate = self; 
     longPressRecognizer.minimumPressDuration = 0.0; 
     [self.rightSideView addGestureRecognizer:longPressRecognizer]; 
    } 
} 

- (void)handleLeftSidePan:(UIPanGestureRecognizer *)panRecognizer 
{ 
    [self handleGameScreenPan:panRecognizer withVirtualController:&g_iPadVirtualController[0]]; 
} 

- (void)handleRightSidePan:(UIPanGestureRecognizer *)panRecognizer 
{ 
    [self handleGameScreenPan:panRecognizer withVirtualController:&g_iPadVirtualController[1]]; 
} 

- (void)handleLeftSideLongPress:(UILongPressGestureRecognizer *)longPressRecognizer 
{ 
    [self handleGameScreenLongPress:longPressRecognizer withVirtualController:&g_iPadVirtualController[0]]; 
} 

- (void)handleRightSideLongPress:(UILongPressGestureRecognizer *)longPressRecognizer 
{ 
    [self handleGameScreenLongPress:longPressRecognizer withVirtualController:&g_iPadVirtualController[1]]; 
} 
相关问题