我想模糊游戏背景
self.view?.scene?.paused = true
但是按钮和暂停的标签(均为SKSpriteNode的标签)不应模糊。它们都有不同的Z-index值。
当按下按钮节点时,场景将暂停;当再次按下按钮时,场景将恢复。
我找不到在Swift中实现此目标的方法。
我发现了一些使用SKEffectNode的建议?
最佳答案
基本步骤...
和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)
关于iphone - 如何模糊除2个节点以外的所有内容。 Spritekit( swift ),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26385156/