我有这个精灵,我试图检测用户是否触摸它并发布一个 NSLOG。我已经阅读了一些关于在 stackoverflow 上检测精灵触摸的 cocos2d 帖子,但我有点困惑,不太明白。任何帮助将不胜感激。我将在下面发布我的精灵。
chew = [CCSprite spriteWithFile:@"chew.png" rect:CGRectMake(0, 0, 152, 152)];
chew.position = ccp(100, 300);
[self addChild:chew];
弄清楚了
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
if (CGRectContainsPoint( [ chew boundingBox], location))
{
NSLog(@"touched");
}
}