Blurring a SKShapeNode incrementally using SKEffectNode

ios, skeffectnode, sprite-kit, swift

Solution

Implement the `update` method in your `SKScene` subclass (or delegate). Then, over the course of one second, run this line again each time your `update` method is called:

filter.setValue(10, forKey: "inputRadius")

Except instead of passing the value `10`, interpolate between 0 and 10 based on the elapsed time.

You might find that re-rendering a blur every frame makes it hard to keep a smooth frame rate. So you might consider faking it instead. Make two nodes, one of which has the blur effect, and use `fadeInWithDuration`/`fadeOutWithDuration` actions to fade in the blurred node and fade out the unblurred node.

Problem

I'm trying to blur a SKShapenode in my program. However, I want the shapenode to blur progressively, with a duration of about 1 second. How do I achieve that? The current code blurs it instantly. ``` func generateAnimation() { var blurAction : SKAction = SKAction.runBlock{ //the method below returns a shapeNode var circle = self.generateImage() var effect : SKEffectNode = SKEffectNode() var filter : CIFilter = CIFilter(name:"CIGaussianBlur") filter.setValue(10, forKey: "inputRadius") effect.filter = filter effect.addChild(circle) self.addChild(effect) } ```

Original source