【问题标题】:Issue with SKEmitterNode?SKEmitterNode 的问题?
【发布时间】:2017-06-22 15:19:44
【问题描述】:

所以我的一个 SKEmitterNode 有问题。我有一个 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 的方法,但似乎没有任何效果。

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

-马特

【问题讨论】:

    标签: swift swift3 sprite-kit skemitternode


    【解决方案1】:

    很明显,粒子系统是通过点击测试而不是按钮来检测的。您可以使用 nodes(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")
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-11
      相关资源
      最近更新 更多