Touching a CGRect

Posted by Coder404 on Game Development See other posts from Game Development or by Coder404
Published on 2012-07-07T15:03:30Z Indexed on 2012/07/07 15:23 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

In my cocos2d app I am trying to determine when a CCSprite is touched Here is what I have:

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init];
for (CCSprite *target in _targets) {
    CGRect targetRect = CGRectMake(target.position.x - (target.contentSize.width/2), 
                                   target.position.y - (target.contentSize.height/2), 
                                   27, 
                                   40);


CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
if (CGRectContainsPoint(targetRect, touchLocation)) {            
    NSLog(@"Moo cheese!");
    }
}
return YES;   
}

For some reason it does not work. Can someone help me?

© Game Development or respective owner

Related posts about cocos2d-iphone

Related posts about ios