所以我在我的游戏中有一个暂停按钮,当你按下它时,场景就会暂停,除了一个SKNode (暂停菜单)之外的所有东西都会变得模糊。为此,我创建了一个具有过滤器的SKEffectNode,并将除pause菜单之外的所有内容都添加到其中。它可以工作,但它需要2秒才能让模糊出现在背景中。只要按下按钮,场景就会暂停,但模糊和暂停菜单只会在几秒钟后出现。有什么想法吗?
代码如下:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
if (self.nodeAtPoint(location).name == "PauseButton"){
if(!scene!.paused) {
blurScene()
scene!.paused = true
self.addChild(pauseMenu!)
}else {
removeBlur()
scene!.paused = false
pauseMenu!.removeFromParent()
}
}
}
}
func blurScene() {
blurNode = SKEffectNode() //Created in the beginning of the class
let blur = CIFilter(name: "CIGaussianBlur", withInputParameters: ["inputRadius": 15.0])
blurNode!.filter = blur
self.shouldEnableEffects = true
for node in self.children {
node.removeFromParent()
blurNode!.addChild(node as! SKNode)
}
self.addChild(blurNode!)
}
func removeBlur() {
var blurredNodes = [SKNode]()
for node in blurNode!.children {
blurredNodes.append(node as! SKNode)
node.removeFromParent()
}
for node in blurredNodes {
self.addChild(node as SKNode)
}
self.shouldEnableEffects = false
blurNode!.removeFromParent()
}发布于 2019-09-04 03:26:27
尝试将SKEffectNode添加为根视图,并将子节点添加到其中。然后你就可以设置模糊滤镜了
self.shouldEnableEffects = false当你想简单地模糊的时候
self.shouldEnableEffects = truehttps://stackoverflow.com/questions/32597480
复制相似问题