2012-07-13 89 views
0

我有2个CCLayer堆叠在一起;两者都启用触摸。我希望顶层CCLayer响应并消费触摸,底层不会对顶层消耗的触摸作出反应。支持多点触控的CCLayers,顶层不消耗触摸

顶层具有看起来像这样一个CCTouchBegan方法:

- (BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{ 
    NSLog(@"touched!"); 

    CGPoint location = [touch locationInView:[touch view]]; 
    location = [[CCDirector sharedDirector] convertToGL:location]; 

    //DO STUFF WITH TOUCH 

    return YES; 
} 

底层具有CCTouchesEnded方法,看起来像这样:

- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    //choose one of the touches to work with 
    UITouch *touch = [touches anyObject]; 
    CGPoint location = [touch locationInView:[touch view]]; 
    location = [[CCDirector sharedDirector] convertToGL:location]; 

    //DO STUFF WITH THE TOUCH 
} 

结果,顶层确实不会消耗触觉,甚至不会对它们做出反应。只有底层才会响应触摸。

+0

我们需要更多信息来回答你的问题。这些图层包含哪些内容?他们如何建立?他们在哪里被添加到屏幕上? – 2012-07-13 19:51:48

+0

@DustinRowland完成。 – TheDanman 2012-07-13 20:55:16

+0

@TheDanman是否重视哪个层“消耗”触摸? – 2012-07-13 21:18:59

回答

0

在您使用CCTargetedTouchDelegate方法的第一层中。 CCLayer将自己注册为CCStandardTouchDelegate。这就是为什么你的第二层响应触摸。

+0

有什么办法可以将CCLayer注册为CCTargetedTouchDelegate? – TheDanman 2012-07-13 22:13:39

+0

使用搜索。 http://stackoverflow.com/questions/11056222/touch-handled-by-two-layers – Morion 2012-07-14 03:16:15