How to blur everything except 2 nodes. Spritekit (Swift) How to blur everything except 2 nodes. Spritekit (Swift) xcode xcode

How to blur everything except 2 nodes. Spritekit (Swift)


The basic steps...

  1. Create an SKEffectsNode
  2. Create a CIGaussianBlur CIFilter
  3. Assign the filter to the effects node
  4. 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)