6
votes

I create a SKSpriteNode just with a fill color and a size, then I rotate it:

SKSpriteNode *myNode = [SKSpriteNode spriteNodeWithColor:[SKColor grayColor] size:CGSizeMake(100, 100)];

myNode.zRotation = 0.2 * M_PI;

How do I enable anti-aliasing for my SKSpriteNode? Right now, the edges of the gray square look jagged.

What I already found out: When I create a gray 100x100px PNG and use spriteNodeWithImageNamed:, the edges look jagged, too. If I add a 1px transparent border around the gray square PNG, the edges look smooth. (Since the jagged edges are now transparent.)

Thank you in advance for your help!

1
You can set texture filtering on SKTexture developer.apple.com/library/ios/documentation/SpriteKit/…. Not sure if your node will have texture since it is generated with colour and size, but it is worth a try.Dobroćudni Tapir
Thanks, but this doesn't work without a SKTexture. (And "SKTextureFilteringLinear" should be the default anyway.)user867635
@Sebastian Found any solution yet ?bobmoff
@bobmoff: Nope, unfortunately not. And I don't think you can do anything about that. If you use TexturePacker for you spritesheets, there is an option Inner padding to add transparent pixels around your images. It says: "It considerably reduces aliasing along the polygon edges when rotating trimmed or cropped sprites. E.g. if your sprite has many pixels along its own boundaries, it will be drawn more smoothly when rotating it."user867635
@Sebastian, Ok thanks for the explanation.bobmoff

1 Answers

0
votes

I know this question is very old, but I have a simple solution. Maybe is your image that do not scale well. Vector images, with large curve surfaces, present a challenge to resize.

What I do is: 1) If you import a vector file, be sure to transform it to PNG, using a very large DPI (360), and size; 2) Open the PNG using Gimp; 3) Apply a Gaussian blur with factor 11 (or greater).

Now, use your image as a Texture. If it is still jagged, then set usesMipmaps to true.