我有 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
}
结果是顶层根本不消耗触摸甚至响应它们。只有底层响应触摸。