cocos2d 2.0.0 でタップイベントを検出


cocos2d 2.0.0でタップイベントを検知する方法です。0.99の頃とは2の部分が変わっているのでご注意ください。

1. HogeLayerのinitでisTouchEnabledにYESを設定

-(id) init
{
    if( (self=[super init]) ) {
        self.isTouchEnabled = YES;
    }
}

2. HogeLayerに以下のメソッドを追加

-(void) registerWithTouchDispatcher
{
    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
{
}

Comments

comments

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です