正如许多其他人在网上建议的那样,我正在尝试为图层启用触摸功能:
hudLayer = [[[CCLayer alloc] init] autorelease];
[self addChild:hudLayer z:3];
gameLayer = [[[CCLayer alloc] init] autorelease];
[self addChild:gameLayer z:1];
gameLayer.isTouchEnabled = YES;
rileyLayer = [[[CCLayer alloc] init]autorelease];
[self addChild:rileyLayer z:2];
pauseMenu = [[[CCLayer alloc] init] autorelease];
[self addChild:pauseMenu z:4];
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:hudLayer priority:0 swallowsTouches:YES];
我的触摸方法在这里:
- (BOOL)ccTouchBegan:(NSSet *)touch withEvent:(UIEvent *)event {
return TRUE;
}
- (void)ccTouchEnded:(NSSet *)touch withEvent:(UIEvent *)event {
if (!paused) {
ratMove = 0;
}
}
但是,这会不断引发错误:由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“Layer#ccTouchBegan override me”
我可以在线找到此错误的唯一原因是,如果您没有包含 ccTouchBegan 功能,但是我是,有其他人知道出现此错误的任何其他原因吗?