I need to detect touches in a circular shape, the problem is that while the shape looks like a circle the touchable area is still rectangular. How do I detect touches only if the user touches my circle?
This is what I'm doing now:
// Here I add the Shape
_circle = [SKShapeNode node];
_circle.name = @"circle";
_circle.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[_circle setPath:CGPathCreateWithRoundedRect(CGRectMake(-70, -70, 140, 140), 70, 70, nil)];
_circle.strokeColor = _circle.fillColor = [UIColor colorWithRed:255.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:1.0];
[self addChild:_circle];
//...
// Listening to touches
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
if (CGRectContainsPoint(_circle.frame, location)) {
NSLog(@"Circle is touched");
}
}