I'd like to blur the background of my game when
self.view?.scene?.paused = true
But the the button and the paused label (both SKSpriteNode's) should not be blur. they all have different Z-index values. The scene is paused when the button node is pressed and resumed when the button is pressed again.
I cant find a way to achieve this in Swift. i found some suggestions that use SKEffectNode?
The basic steps...
and example code in Swift...
// Create an effects node with a gaussian blur filter
let effectsNode = SKEffectNode()
let filter = CIFilter(name: "CIGaussianBlur")
// Set the blur amount. Adjust this to achieve the desired effect
let blurAmount = 10.0
filter?.setValue(blurAmount, forKey: kCIInputRadiusKey)
effectsNode.filter = filter
effectsNode.position = self.view!.center
effectsNode.blendMode = .alpha
// Create a sprite
let texture = SKTexture(imageNamed: "Spaceship")
let sprite = SKSpriteNode(texture: texture)
// Add the sprite to the effects node. Nodes added to the effects node
// will be blurred
effectsNode.addChild(sprite)
// Add the effects node to the scene
self.addChild(effectsNode)
// Create another sprite
let sprite2 = SKSpriteNode(texture: texture)
sprite2.position = self.view!.center
sprite2.size = CGSize(width:64, height:64);
sprite2.zPosition = 100
// Add the sprite to the scene. Nodes added to the scene won't be blurred
self.addChild(sprite2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With