我有几个图层并向它们添加了一些精灵;尝试以这种方式访问它们:
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
if(CGRectContainsPoint([[self getChildByTag:tagNumber] boundingBox], location)) {
CCLOG(@"You've touched the sprite!");
}
}
奇怪的是,如果没有这个方法:
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
当我触摸屏幕时,我的应用程序崩溃了。知道可能是什么吗?
更新:
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self
priority:0 swallowsTouches:YES];
}