ヘッダー
@interface SpriteWithTouch : CCSprite <CCTouchOneByOneDelegate>
実装
- (void) onEnter {
[super onEnter];
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInView:touch.view];
CGPoint location = [[CCDirector sharedDirector] convertToGL:touchLocation];
//CCSpriteの描画領域でタッチされているか判定
if (CGRectContainsPoint(self.boundingBox, location)) {
CCLOG(@"touch!");
return YES;
} else {
return NO;
}
}
- (void) onExit {
[super onExit];
[[[CCDirector sharedDirector] touchDispatcher] removeDelegate:self];
}
0 件のコメント:
コメントを投稿