私はいくつかのレイヤーを持っていて、それらにいくつかのスプライトを追加しました。この方法でそれらにアクセスしようとしています:
-(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];
}