我试图使用以下片段创建一个模糊效果:
let glowEffectNode = SKEffectNode()
glowEffectNode.shouldRasterize = true
let glowSize = CGSize(width: barSize.width, height: barSize.height)
let glowEffectSprite = SKSpriteNode(color: barColorData.topColor, size: glowSize)
glowEffectNode.addChild(glowEffectSprite)
let glowFilter = CIFilter(name: "CIGaussianBlur")
glowFilter!.setDefaults()
glowFilter!.setValue(5, forKey: "inputRadius")
glowEffectNode.filter = glowFilter当然,在iOS 8.x上,它工作得很好,但是从iOS 9.x (在9.0和9.1上都试过)来看,模糊功能不能正常工作。(在模拟器中,节点似乎有点透明,但绝对不是模糊的;在设备上,它似乎模糊,但被裁剪,并且与其中心位置也有一个偏移:/)
是否有一种使用CIFilter快速修复此问题的方法?
发布于 2015-11-01 21:37:40
我用这个做了更多,找到了一个解决办法.
首先,对模糊半径使用奇数似乎会使整个节点呈现为偏移量(?)例如,使用10来解决偏移量问题。
第二,由于整个节点都是呈现的sprite,因此,对于模糊效果,您需要额外的空间,因此我使用透明的sprite作为额外的空间,下面的代码片段现在可以工作了:
let glowEffectNode = SKEffectNode()
glowEffectNode.shouldRasterize = true
let glowBackgroundSize = CGSize(width: barSize.width + 60, height: barSize.height + 60)
let glowSize = CGSize(width: barSize.width + 10, height: barSize.height + 10)
let glowEffectSprite = SKSpriteNode(color: barColorData.topColor, size: glowSize)
glowEffectNode.addChild(SKSpriteNode(color: SKColor.clearColor(), size: glowBackgroundSize))
glowEffectNode.addChild(glowEffectSprite)
let glowFilter = CIFilter(name: "CIGaussianBlur")
glowFilter!.setDefaults()
glowFilter!.setValue(10, forKey: "inputRadius")
glowEffectNode.filter = glowFilter我应该提到,为了提高效率,我正在使用view.textureFromNode(glowEffectNode)从这个节点创建一个纹理,但是我尝试使用节点本身,问题仍然存在,所以不管怎么说,上面的内容都应该有效。
https://stackoverflow.com/questions/33455823
复制相似问题