How to blur everything except 2 nodes. Spritekit (Swift)
The basic steps...
- Create an SKEffectsNode
- Create a CIGaussianBlur CIFilter
- Assign the filter to the effects node
- Add nodes to the effects node (child nodes will be blurred)
and example code in Swift...
// Create an effects node with a gaussian blur filterlet effectsNode = SKEffectNode()let filter = CIFilter(name: "CIGaussianBlur")// Set the blur amount. Adjust this to achieve the desired effectlet blurAmount = 10.0filter?.setValue(blurAmount, forKey: kCIInputRadiusKey)effectsNode.filter = filtereffectsNode.position = self.view!.centereffectsNode.blendMode = .alpha// Create a spritelet texture = SKTexture(imageNamed: "Spaceship")let sprite = SKSpriteNode(texture: texture)// Add the sprite to the effects node. Nodes added to the effects node// will be blurredeffectsNode.addChild(sprite)// Add the effects node to the sceneself.addChild(effectsNode)// Create another spritelet sprite2 = SKSpriteNode(texture: texture)sprite2.position = self.view!.centersprite2.size = CGSize(width:64, height:64);sprite2.zPosition = 100// Add the sprite to the scene. Nodes added to the scene won't be blurredself.addChild(sprite2)