我需要检测圆形的触摸,问题是虽然形状看起来像圆形,但可触摸区域仍然是矩形。仅当用户触摸我的圈子时,我如何检测触摸?
这就是我现在正在做的事情:
// 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");
}
}