SKEmitterNode问题?

时间:2017-06-22 15:19:44

标签: swift swift3 sprite-kit skemitternode

所以我遇到了一个我的SKEmitterNodes问题。我有一个SKSpriteNode,当触摸时会打开一个新场景。这是触摸开始的代码:

 for touch: AnyObject in touches {
        let location = (touch as! UITouch).location(in: self)
        if let nodeName = self.atPoint(location).name {

            if nodeName == "playBox" || nodeName == "playButton" {
                buttonSound()
                pulse(playBox, scene: "GameScene")
            }else if nodeName == "shopBox" || nodeName == "shopButton"{
                buttonSound()
                pulse(shopBox, scene: "shop")
            }}}

此时,一切都很好。将我的SKEmitterNode添加到场景时出现问题。发射器是星场效应,因此从场景顶部到底部的点很少。一旦我添加了这个发射器,我的按钮就会停止工作!

我尝试过降低生成率,降低zPosition,但似乎没有任何效果。

如果您有任何建议,请告诉我。谢谢!

-Matt

1 个答案:

答案 0 :(得分:1)

显然,点击测试而不是按钮检测到粒子系统。您可以使用节点(at:)来获取该点中所有节点的列表(而不仅仅是第一个节点)。然后,您需要迭代或过滤该数组,并找出哪些节点是按钮。

for touch: AnyObject in touches 
{
    let location = (touch as! UITouch).location(in: self)
    let nodes = self.nodes(at:location)

    let filtered1 = nodes.filter{ $0.name == "playBox" || $0.name == "playButton" }
    let filtered2 = nodes.filter{ $0.name == "shopBox" || $0.name == "shopButton" }

    if let node = filtered1.first {
        buttonSound()
        pulse(playBox, scene: "GameScene")
    }

    if let node = filtered2.first {
        buttonSound()
        pulse(shopBox, scene: "shop")
    }