I have a number of Atlas Sprites that I have running down the screen. I want to have it where if they are touched something happens. This is pretty simple and I have the code, but it appears as if the tapping is always offset to the upper right for some reason.
NOTE: I am going through an array of sprites and doing CGRectContainsPoint
Here is my code (FYI this is a portrait game).
code
- (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if( touch ) {
CGPoint location = [touch locationInView: [touch view]];
CGPoint convertedPoint = [[Director sharedDirector] convertCoordinate:location];
CGPoint finger = CGPointMake(convertedPoint.x,convertedPoint.y);
for(int i=1; i<[spriteList count]; i++)
{
AtlasSprite *sprite = (AtlasSprite *) [spriteList objectAtIndex:i];
CGRect spriteRect = CGRectMake(sprite.position.x, sprite.position.y, sprite.contentSize.width, sprite.contentSize.height);
if (CGRectContainsPoint(spriteRect,finger))
{
NSLog(@"Oh, you touched it! %f, %f, %@",sprite.position.x,sprite.position.y,[self numberToLetter:[sprite tag]]);
// we stop the all running actions
[sprite stopAllActions];
return kEventHandled;
}
}
}
return kEventIgnored;
}