【问题标题】:SKShapeNode with UIBezierPath is not filled entirely带有 UIBezierPath 的 SKShapeNode 未完全填充
【发布时间】:2015-01-22 19:48:31
【问题描述】:

我想使用带有 UIBezierPath 的 SKShapeNode 绘制一个圆形的填充扇区。 在大多数情况下,我的效果都很好,但是对于较小的角度,形状并没有完全填充(在弧线下方有一点间隙)。像这样:

这是我使用的代码:

CGPoint center = CGPointMake(500, 300) ;

UIBezierPath *bezierPath = [UIBezierPath bezierPath];
[bezierPath addArcWithCenter:center radius:400   startAngle:1.825777 endAngle:2.011118 clockwise:YES];
[bezierPath addLineToPoint:center];
[bezierPath closePath];

SKShapeNode *shapeNode = [SKShapeNode shapeNodeWithPath:bezierPath.CGPath];
shapeNode.strokeColor = [UIColor whiteColor];
shapeNode.fillColor = [UIColor whiteColor];
[self addChild:shapeNode];

iPad 和模拟器 (iOS 8.1) 上的结果相同。

是我做错了什么还是一些限制或错误?

如果无法使用这些 API 更准确地绘制此形状,您能否建议一些其他方法在 SpriteKit 游戏的上下文中绘制它。

提前谢谢你。

【问题讨论】:

    标签: ios sprite-kit uibezierpath


    【解决方案1】:

    这可能是一个 SKShapeNode 错误,请参阅 http://sartak.org/2014/03/skshapenode-you-are-dead-to-me.html

    一种解决方法是增加 SKShapeNode 的 lineWidth 以填补空白。

    shapeNode.lineWidth = 4

    您可以改为使用相同的 bezierPath 对 UIKit 执行相同操作,并在 drawRect 中填充和描边。

    【讨论】:

    • 我需要这个形状成为一个 SpriteKit 节点,而不是简单地绘制它。我不明白如何使用 drawRect 来实现它。能否请您详细描述一下。
    • 我现在无法测试它,但我相信我遇到了 lineWidth > 4 的问题
    • @akmidd for drawRect 抱歉,您将无法在 SpriteKit 节点中使用它,我们的想法是放弃 SpriteKit 并在 UIKit 中完成所有动画/绘图。
    • 我尝试使用 Core Graphics 将我的形状绘制到 UIImage 中,然后将其用作 SKSpriteNode 的纹理。这种方式可以完美地渲染形状,但是当需要实时生成多个节点时,性能会明显下降。所以现在我回滚到使用 SKShapeNode 但从我的形状中排除了弧。我猜,因为 CoreGraphics > UIImage > SKSpriteNode 不是性能关键任务可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2019-12-09
    • 1970-01-01
    • 2020-04-21
    相关资源
    最近更新 更多