2

When I change SKShapeNode's .alpha, its stroke shows itself as if .strokeColor of node was brighter than its .fillColor. Setting .lineWidth to 0 canceles antialiased smotheness that the stroke provides. Same does setting .strokeColor to SKColor.clearColor.

SKShapeNode stroke alpha issue

Question

What is the best way to make stroke look the same as fill when changing node.alpha, preserving the antialiased smootheness of edges?

kerd
  • 307
  • 2
  • 13
  • 1
    have you checked this ? http://stackoverflow.com/a/26640893/4078517 – Darvas Nov 03 '15 at 19:04
  • @Darvydas thank you, this worked. The idea is to get HSBA of `.strokeColor` like this http://stackoverflow.com/questions/10071756/is-there-function-to-convert-uicolor-to-hue-saturation-brightness then change alpha to desired – kerd Nov 03 '15 at 19:21
  • I just posted a link, not an answer :). You can post answer and mark it :) – Darvas Nov 03 '15 at 19:39
  • @Darvydas I have encountered another problem on this way. As the node's fill covers node's stroke, stroke's alpha must be set to 0 so that it actually wouldn't be seen. But this canceles antialiasing. So actually it does not work. I guess the only way is to convert SKShapeNode to SKSpriteNode. – kerd Nov 03 '15 at 19:50

1 Answers1

1

Though it is possible to set alpha of node's stroke directly by getting its' colors' HSBA and reassigning a new color with different alpha to the stroke (for more info look this answer), as the node's fill covers node's stroke, stroke's alpha must be set to 0 so that it actually wouldn't be seen. But this canceles antialiasing.

So it appears, that the only way to achieve smooth node's edges with no stroke be seen, is to convert SKShapeNode to SKSpriteNode and reset sprite.alpha to desired.

smooth

Here is a code snippet in Swift

let sprite = SKSpriteNode(texture: self.view!.textureFromNode(shapeNode))

Its' not that bad, because, according to Apple's docs

The node being rendered does not need to appear in the view’s presented scene.

However, you still have to have access to the view from where the conversion takes place.

Community
  • 1
  • 1
kerd
  • 307
  • 2
  • 13