如何模糊除 2 个节点之外的所有内容。雪碧 (Swift)

2024-04-03

我想模糊我的游戏背景

self.view?.scene?.paused = true

但是按钮和暂停的标签(都是 SKSpriteNode 的)不应该是模糊的。它们都有不同的 Z-index 值。 按下按钮节点时场景暂停,再次按下按钮时场景恢复。

我找不到在 Swift 中实现这一目标的方法。 我发现了一些使用 SKEffectNode 的建议?


基本步骤...

  1. 创建 SKEffectsNode
  2. 创建 CIGaussianBlur CIFilter
  3. 将过滤器分配给效果节点
  4. 添加节点到效果节点(子节点会被模糊)

以及 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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何模糊除 2 个节点之外的所有内容。雪碧 (Swift) 的相关文章

随机推荐