gpt4 book ai didi

iphone - 如何模糊除 2 个节点之外的所有内容。 Spritekit( swift )

转载 作者:IT王子 更新时间:2023-10-29 05:36:29 25 4
gpt4 key购买 nike

我想在什么时候模糊我的游戏背景

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)

关于iphone - 如何模糊除 2 个节点之外的所有内容。 Spritekit( swift ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26385156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com