有可能得到SKShapeNode的半径值吗?
问题是,在用户发布后,我需要创建一个相同的圆圈,同时从视图中删除第一个圆圈。
SKShapeNode *reticle = [SKShapeNode shapeNodeWithCircleOfRadius:60];
reticle.fillColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
reticle.strokeColor = [UIColor clearColor];
reticle.position = CGPointMake(location.x - 50, location.y + 50);
reticle.name = @"reticle";
reticle.userInteractionEnabled = YES;
[self addChild:reticle];
[reticle runAction:[SKAction scaleTo:0.7 duration:3] completion:^{
[reticle runAction:[SKAction scaleTo:0.1 duration:1]];
}];然后
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
....
SKNode *node = [self childNodeWithName:@"reticle"];
//take the position of the node, draw an imprint
/////////Here is where I need to get the circle radius.
[node removeFromParent];
}如何取圆半径,这样我就可以说
SKShapeNode *imprint = [SKShapeNode shapeNodeWithCircleOfRadius:unknownValue];我试过了,做了一个精确的圆圈副本
SKShapeNode *imprint = (SKShapeNode *)node;然而,这仍然跟随动画,因为我需要它停止,在这一点上它是在。我不想采取"stopAllAnimations“的方法。
发布于 2015-07-05 19:38:33
可以使用形状节点的path属性使用CGPathGetBoundingBox(path)确定形状的边框。从边界开始,你可以用宽度(或高度)除以2来计算圆的半径。
CGRect boundingBox = CGPathGetBoundingBox(circle.path);
CGFloat radius = boundingBox.size.width / 2.0;发布于 2019-06-15 17:20:15
更新Swift 5
myVariable.path.boundingBox.width / 2https://stackoverflow.com/questions/31233428
复制相似问题