时,我想模糊游戏的背景
self.view?.scene?.paused = true
但是按钮和暂停的标签(两个SKSpriteNode)都不应该模糊。它们都有不同的Z指数值。 按下按钮节点时暂停场景,再次按下按钮时恢复场景。
我无法在Swift中找到实现这一目标的方法。 我找到了一些使用SKEffectNode的建议?
答案 0 :(得分:10)
基本步骤......
和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)