如何模糊除2个节点之外的所有内容Spritekit(Swift) [英] How to blur everything except 2 nodes. Spritekit (Swift)

查看:185
本文介绍了如何模糊除2个节点之外的所有内容Spritekit(Swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望模糊游戏的背景

self.view?.scene?.paused = true

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

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.

我无法在Swift中找到实现此目的的方法。
i找到了一些使用SKEffectNode的建议?

I cant find a way to achieve this in Swift. i found some suggestions that use SKEffectNode?

推荐答案

基本步骤......

The basic steps...


  1. 创建SKEffectsNode

  2. 创建CIGaussianBlur CIFilter

  3. 将过滤器分配给效果节点

  4. 向节点节点添加节点(子节点将模糊)

  1. Create an SKEffectsNode
  2. Create a CIGaussianBlur CIFilter
  3. Assign the filter to the effects node
  4. Add nodes to the effects node (child nodes will be blurred)

和示例代码在Swift ...

and example code in 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)

这篇关于如何模糊除2个节点之外的所有内容Spritekit(Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆