cocos2d 2.0.0でタップイベントを検知する方法です。0.99の頃とは2の部分が変わっているのでご注意ください。
1. HogeLayerのinitでisTouchEnabledにYESを設定
-(id) init
{
if( (self=[super init]) ) {
self.isTouchEnabled = YES;
}
}
{
if( (self=[super init]) ) {
self.isTouchEnabled = YES;
}
}
2. HogeLayerに以下のメソッドを追加
-(void) registerWithTouchDispatcher
{
CCDirector *director = [CCDirector sharedDirector];
[[director touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
{
CCDirector *director = [CCDirector sharedDirector];
[[director touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
3. 実際の処理を記述する。
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
}
-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
}
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
}
{
return YES;
}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
}
-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
}
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
}