SKCropNode masking edge anti-aliasing
Asked Answered
P

3

14

I created a circular mask and animate a sprite inside the mask by using sprite kit SKCropNode class. But the edge of the mask looks pixellated.

Is there a way to use anti-aliasing to smooth the edges?

Prenatal answered 16/12, 2013 at 19:35 Comment(3)
could you share the code you used to achieve the mask?Headache
does is appear pixelated on the simulator only or the device too??Ferri
According to specs, it will definitely have jagged edges, as the SKCropNode uses a boolean (0 or 1) alpha value, not a byte value (say, 0 to 255).Morgan
G
7

If you want to mask any SKNode/SKSpriteNode with an anti-aliasing effect - you can use SKEffectNode instead of SKCropNode. It works with animated nodes as well. Here is an example:

// Set up your node
SKNode *nodeToMask = [SKNode node];
// ...

// Set up the mask node
SKEffectNode *maskNode = [SKEffectNode node];

// Create a filter
CIImage *maskImage = [[CIImage alloc] initWithCGImage:[UIImage imageNamed:@"your_mask_image"].CGImage];
CIFilter *maskFilter = [CIFilter filterWithName:@"CISourceInCompositing"
                                  keysAndValues:@"inputBackgroundImage", maskImage, nil];
// Set the filter
maskNode.filter = maskFilter;

// Add childs
[maskNode addChild:nodeToMask];
[scene addChild:maskNode];
Greatuncle answered 2/9, 2015 at 9:18 Comment(0)
M
3

From the official docs:

If the pixel in the mask has an alpha value of less than 0.05, the image pixel is masked out.

So, SKCropNode doesn't support per pixel alpha values. It either draws the pixels or it doesn't. If alpha (as is used by anti-aliasing) is important to you, you should consider alternative routes. For example:

How to Mask an UIImageView

Morgan answered 30/12, 2013 at 13:11 Comment(0)
S
-1

As of now (June 2018) I can confirm that the SKCropNode will do per-pixel alpha blending. If the crop node has an SKSpriteNode as a mask, and the mask node uses a texture with an anti-aliased mask image, the crop node will do the proper blending.

Sizeable answered 5/6, 2018 at 20:41 Comment(1)
That's not what I'm seeing my man. October 2018. Perhaps you can expand on this?Kyne

© 2022 - 2024 — McMap. All rights reserved.