Dmitry Klochkov
Dmitry Klochkov

Reputation: 2635

SKShapeNode with UIBezierPath is not filled entirely

I want to draw a filled sector of a circle using SKShapeNode with UIBezierPath. I works well in most cases, but with smaller angles the shape is not filled entirely(right under the arc there is a little gap). Like this:

enter image description here

Here is the code I use:

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];

The result is the same on iPad and on the simulator (iOS 8.1).

Am I doing something wrong or it is some limitation or bug?

If it's not possible to draw this shape more accurately with these API, could you please suggest some other ways to draw it in the context of SpriteKit game.

Thank you in advance.

Upvotes: 3

Views: 1781

Answers (1)

netbe
netbe

Reputation: 236

It could be a SKShapeNode bug, see http://sartak.org/2014/03/skshapenode-you-are-dead-to-me.html

One fix, would be to increase the lineWidth of the SKShapeNode so it fills up the gap.

shapeNode.lineWidth = 4

You could instead do the same with UIKit using the same bezierPath and fill and stroke it in drawRect.

Upvotes: 2

Related Questions