SKShapeNode, antialiasing with fill, no stroke

I'm trying to render SKShapeNodes with very thin, precise shapes. I also want antialiasing, because it looks much better. Unfortunately, it appears that antialiasing only works if you stroke the path, which in turn throws off the shape precision. I tried setting a very small lineWidth on the node (0.1) but that appears to be ignored once it goes below a certain width. I can't get thin, antialiased shapes. Is there a way?


I see a property on SKShapeNode called `fillShader: SKShader`. Maybe if I learn about those there is a way to get back the antialiasing without the stroked path? I have yet to write my own shader code so I'm not sure what's possible.


Or maybe I need to render the shape to an image with Core Graphics, then use that image for an SKSpriteNode.


Rob

Accepted Reply

SKShapeNode has always been unusable for any serious purpose. Even if you can get it to render un-horribly, performance is abysmal. (I admit, though, that I stopped using SKShapeNode several years ago. Maybe it's been improved, but it doesn't sound like it.)


>> maybe I need to render the shape to an image with Core Graphics, then use that image for an SKSpriteNode


This works fine, at least if you're not rendering the shape yourself every frame, and perhaps even if you are, sometimes. "UIGraphicsBeginImageContextWithOptions" — specifying 0 for the scale — is your friend.

Replies

SKShapeNode has always been unusable for any serious purpose. Even if you can get it to render un-horribly, performance is abysmal. (I admit, though, that I stopped using SKShapeNode several years ago. Maybe it's been improved, but it doesn't sound like it.)


>> maybe I need to render the shape to an image with Core Graphics, then use that image for an SKSpriteNode


This works fine, at least if you're not rendering the shape yourself every frame, and perhaps even if you are, sometimes. "UIGraphicsBeginImageContextWithOptions" — specifying 0 for the scale — is your friend.

Thanks. I'm using SKSpriteNode now and it's working better.

In the last app I developed I went nuts with SKShapeNodes. I made everything I could with them, specifically all interface elements and icons. I was so proud that everything was code until we started to get into big trouble with performance, and ultimately crashes. Now I just finished ripping all of them out from the app, replacing them with classic SKSpriteNodes. I'm even prouder now to have everything back to normal and the app functioning as it should.


Earlier, I didn't mind the stroke aliasing, visually. One big gripe was that the stroke would not follow the alpha value of the shape, so animating the transparency for example was terrible. I had to do all sorts of workarounds to make them do what I wanted. Happily I'm not touching them ever again. My experience is with up to iOS 11, Xcode 9 and Swift 4, so it doesn't seem like shapes have improved. Never again!