gpt4 book ai didi

ios - 如何在 Swift 2 中模糊场景

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:54:41 24 4
gpt4 key购买 nike

当我暂停游戏时,我正在尝试模糊场景并且我正在关注 example但我无法在 Swift 2.0 中解决这个问题。

很多教程都说只截取屏幕截图,然后将该屏幕截图显示为模糊,但我认为这不是一个好主意,我想在没有屏幕截图的情况下模糊 View 。

这是我的尝试:

func createlayers() {
let node = SKEffectNode()
node.shouldEnableEffects = false
let filter: CIFilter = CIFilter(name: "CIGaussianBlur", withInputParameters: ["inputRadius" : NSNumber(double:1.0)])!
node.filter = filter
}

func blurWithCompletion() {
let duration: CGFloat = 0.5
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")

}))
}

func pauseGame()
{
self.blurWithCompletion()
self.view!.paused = true

}

我收到“ fatal error :在展开可选值时意外发现 nil”

最佳答案

创建层方法不是必需的。使用这个更新的 blurWithCompletion 方法:

    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")

}))
}

关于ios - 如何在 Swift 2 中模糊场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35331053/

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