Sprite Kit/ SKShapeNode: excluding overlap of shapes

980 views Asked by At

I'm trying to create a crescent moon effect by using two overlapping circles. My thinking was that I could subtract one from the other, but I'm having trouble executing it.

Here's how I've coded the paths (the second path is overlaps the first one by about half):

SKShapeNode *baseMoon = [[SKShapeNode alloc ]init];
CGMutablePathRef moon = CGPathCreateMutable();

CGPathAddArc(moon, NULL, 0, 0, 50, 0, M_PI*2, YES);
CGPathCloseSubpath(moon);
CGPathAddArc(moon, NULL, 0, 50, 50, 0, M_PI*2, YES);
CGPathCloseSubpath(moon);

baseMoon.path = moon;
CGPathRelease(moon);
baseMoon.lineWidth = size;

baseMoon.strokeColor = [SKColor whiteColor];

Does anyone have an idea of how I can subtract the second path from the first? I've looked into using CGContextClip, but that requires UIGraphicsGetCurrentContext (which XCode warns me may cause instabilities) so I've been searching for another solution.

2

There are 2 answers

1
Rahul Iyer On

You should use SKCropNode. Extra characters so I can submit.

0
Ilea Cristian On

Maybe you should try to draw the path manually. Ray Wenderlich has a great tutorial on this topic.

Another aproach may be to use some CoreImage filter - as I remember, sprite kit does supprt some CoreImage features (see SKEffectNode). In core image there is a subtract-like filter, where you use two images and one is the mask. But I guess that's not what you want.