SKShapeNode.Get 半径?
SKShapeNode.Get Radius?
是否可以获得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" 方法。
您可以使用形状节点的 path
属性 来确定具有 CGPathGetBoundingBox(path)
的形状的边界框。根据边界,您可以通过将宽度(或高度)除以 2 来计算圆的半径。例如,
CGRect boundingBox = CGPathGetBoundingBox(circle.path);
CGFloat radius = boundingBox.size.width / 2.0;
更新 Swift 5
myVariable.path.boundingBox.width / 2
是否可以获得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" 方法。
您可以使用形状节点的 path
属性 来确定具有 CGPathGetBoundingBox(path)
的形状的边界框。根据边界,您可以通过将宽度(或高度)除以 2 来计算圆的半径。例如,
CGRect boundingBox = CGPathGetBoundingBox(circle.path);
CGFloat radius = boundingBox.size.width / 2.0;
更新 Swift 5
myVariable.path.boundingBox.width / 2