添加阴影阴影错误-不能点击我的按钮-SpriteKit

时间:2018-08-11 19:25:34

标签: swift xcode sprite-kit skspritenode

我正在尝试使按钮周围有一个柔和的阴影,以使其看上去有点3d。

我导入了一个普通按钮,并在SKSpriteNode上添加了扩展名

当我单击按钮时,它会转到我的下一个场景(GameScene)。尽管当我应用此“发光”时,它会显示出来,尽管现在无法再按下该按钮了。

let playBtn = SKSpriteNode(imageNamed: "play-btn")
        playBtn.name = "play-btn"
        playBtn.addGlow()
        playBtn.position = CGPoint(x: frame.midX, y: frame.midY + 70)

        addChild(playBtn)

extension SKSpriteNode {

    func addGlow(radius: Float = 10 ) {
        let effectNode = SKEffectNode()
        effectNode.shouldRasterize = true
        addChild(effectNode)
        effectNode.addChild(SKSpriteNode(texture: texture))
        effectNode.filter = CIFilter(name: "CIGaussianBlur", withInputParameters: ["inputRadius":radius])
    }
}

1 个答案:

答案 0 :(得分:0)

效果可能位于按钮上方,阻止您对其进行访问。尝试设置zPosition的(对象的层次)

let playBtn = SKSpriteNode(imageNamed: "play-btn")
playBtn.name = "play-btn"
playBtn.addGlow()
playBtn.position = CGPoint(x: frame.midX, y: frame.midY + 70)
playBtn.zPosition = 1
addChild(playBtn)

extension SKSpriteNode {

    func addGlow(radius: Float = 10 ) {
        let effectNode = SKEffectNode()
        effectNode.shouldRasterize = true
        effectNode.zPosition = -1
        addChild(effectNode)
        effectNode.addChild(SKSpriteNode(texture: texture))
        effectNode.filter = CIFilter(name: "CIGaussianBlur", withInputParameters: ["inputRadius":radius])
     }
}