How Do I Blur a Scene in SpriteKit?

后端 未结 7 959
北恋
北恋 2020-11-28 06:00

How would I add a gaussian blur to all nodes (there\'s no fixed number of nodes) in an SKScene in SpriteKit? A label will be added on top of the scene later, this will be m

7条回答
  •  伪装坚强ぢ
    2020-11-28 06:40

    This is another example of getting this done in swift 2 without the layers:

    func blurWithCompletion() {
    let duration: CGFloat = 0.5
    let filter: CIFilter = CIFilter(name: "CIGaussianBlur", withInputParameters: ["inputRadius" : NSNumber(double:1.0)])!
    scene!.filter = filter
    scene!.shouldRasterize = true
    scene!.shouldEnableEffects = true
    scene!.runAction(SKAction.customActionWithDuration(0.5, actionBlock: { (node: SKNode, elapsedTime: CGFloat) in
        let radius = (elapsedTime/duration)*10.0
        (node as? SKEffectNode)!.filter!.setValue(radius, forKey: "inputRadius")
    
    }))
    

    }

提交回复
热议问题