0

我有 2 个 CCLayer 堆叠在一起;两者都启用了触摸功能。我希望顶层 CCLayer 响应并消耗触摸,而底层不对顶层消耗的触摸做出反应。

顶层有一个 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
}

结果是顶层根本不消耗触摸甚至响应它们。只有底层响应触摸。

4

1 回答 1

0

在您的第一层中,您使用来自 CCTargetedTouchDelegate 的方法。CCLayer 将自身注册为 CCStandardTouchDelegate。这就是为什么你的第二层会对触摸做出反应。

于 2012-07-13T21:34:08.487 回答