1

I am rewriting some of my graphics drawing code from SKShapeNodes to CGContext/CALayers. I am trying to draw a curve with glow in CGContext. This is what I used to have in SpriteKit:

CGPathRef path = …(some path)
SKShapeNode *node = [SKShapeNode node];
node.path = path;
node.glowWidth = 60;

After adding it to the scene with dark-grey background, the result was as follows:

SpriteKit line glow

Is it possible to draw line with such glow using CGContext but without using CIFilters? Normally I will be drawing over an non-blank context background, so I prefer not to use CIFilters after the line was drawn.

I have already tried the "shadow" solution, but the results are far from perfect:

UIGraphicsBeginImageContextWithOptions(frame.size, NO, 1);
CGContextRef context = UIGraphicsGetCurrentContext();
    CGFloat glowWidth = 60.0;
CGContextSetShadowWithColor(context, CGSizeMake(0.0, 0.0), glowWidth, [UIColor whiteColor].CGColor);
CGContextBeginPath(context);
CGContextAddPath(context, path);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextStrokePath(context);

Result (the shadow is hardly visible):

CGContext line shadow

Please let me know if you have some ideas.

jakubr
  • 305
  • 1
  • 8

1 Answers1

0

You can create a SKEffectNode which allows you to apply Core Image filters to all of its children. In other words, you can create a SKEffectNode then add a flower sprite as a child and the SKEffectNode would apply the Core Image effect to the flower sprite.

For more detailed information, please see the SKEffectNode Class Reference.

sangony
  • 11,636
  • 4
  • 39
  • 55
  • 1
    I would like to achieve the glow in `CGContext`/`CALayer`. For some operations I prefer lower-level drawing to better manage the memory used. Also I would like to have the glow for line only, not the whole drawing and this could be easily achieved in `SKShapeNode` using glowWidth property as I mentioned. The problem is that I would like to avoid `SKNode` mechanics for that. I wanted to draw such glow using `CGContext`. – jakubr Apr 18 '14 at 16:50