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.
但是按钮和暂停标签(两个SKSpriteNode)不应该是模糊的。它们都有不同的z指数值。当按钮节点被按下时,场景将被暂停;当按钮再次被按下时,场景将被恢复。
I cant find a way to achieve this in Swift. i found some suggestions that use SKEffectNode?
我找不到一种方法能在短时间内实现这一点。我发现了一些使用SKEffectNode的建议?
1 个解决方案
#1
10
The basic steps...
的基本步骤……
- Create an SKEffectsNode
- 创建一个SKEffectsNode
- Create a CIGaussianBlur CIFilter
- 创建一个CIGaussianBlur CIFilter
- Assign the filter to the effects node
- 将过滤器分配给效果节点
- Add nodes to the effects node (child nodes will be blurred)
- 向effects节点添加节点(子节点将被模糊化)
and example code in Swift...
以及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)
#1
10
The basic steps...
的基本步骤……
- Create an SKEffectsNode
- 创建一个SKEffectsNode
- Create a CIGaussianBlur CIFilter
- 创建一个CIGaussianBlur CIFilter
- Assign the filter to the effects node
- 将过滤器分配给效果节点
- Add nodes to the effects node (child nodes will be blurred)
- 向effects节点添加节点(子节点将被模糊化)
and example code in Swift...
以及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)