gpt4 book ai didi

ios - 带圆角的 Spritekit 线

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:20:03 27 4
gpt4 key购买 nike

我使用 SKShapeNode 绘制一些从 A 点到 B 点的线。线很宽,我需要圆角以使其更漂亮。

经过一些搜索,有一个 CGPathCreateWithRoundedRect,但我不确定它是否可以画对角线。

我尝试在行首和行尾添加一个圆,但结果并不完美,特别是如果我在圆和行上都使用 glowWidth。

这是我画线的方式:

SKShapeNode *yourline = [SKShapeNode node];
CGMutablePathRef pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, from.x, from.y);
CGPathAddLineToPoint(pathToDraw, NULL, to.x, to.y);
yourline.path = pathToDraw;
[yourline setStrokeColor:[UIColor redColor]];
[nodeGridLines addChild:yourline];

我是 spritekit 的新手,也许还有其他方法可以做我想做的事。如果我可以在我的线条上使用一些纹理,那就太好了。

最佳答案

您可以使用 SKShapeNode 的 lineCap 属性。

    UIBezierPath *linePath = [UIBezierPath bezierPath];
[linePath moveToPoint:CGPointMake(500, 300)];
[linePath addLineToPoint:CGPointMake(550, 350)];
SKShapeNode *lineNode = [SKShapeNode shapeNodeWithPath:linePath.CGPath];
lineNode.lineCap = kCGLineCapRound;
lineNode.lineWidth = 10;
[self addChild:lineNode];

结果:

enter image description here

关于ios - 带圆角的 Spritekit 线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26383389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com