【问题标题】:Touch through particle Layer通过粒子层触摸
【发布时间】:2015-11-09 07:33:34
【问题描述】:

我有一个非常简单的粒子设置,其中雨粒子层位于我的整个 SKScene 之上。现在,我只想触摸该层下方的按钮和对象。我怎样才能通过仍然将此层保持在最高 zPosition 上来实现这一点。 (代码如下)

let rainParticlePath = NSBundle.mainBundle().pathForResource("myRainParticles",
            ofType: "sks")

let rainEmitter = NSKeyedUnarchiver.unarchiveObjectWithFile(rainParticlePath!)
            as! SKEmitterNode

rainEmitter.position = CGPointMake(0,screenSize.height)
rainEmitter.zPosition = 200
rainEmitter.userInteractionEnabled = true

self.addChild(rainEmitter)

【问题讨论】:

    标签: swift sprite-kit skemitternode


    【解决方案1】:

    使用nodesAtPoint: 获取所有SKNode 位于您触摸的位置,包括粒子层下方的节点。

    例如:

    let nodes = self.nodesAtPoint(touchLocation)
    for node in nodes {
        if node.name == "button" {
            // Do something to your 'button'
        }
        else if node.name == "object" {
            // Do something to your 'object'
        }
    }
    

    【讨论】:

    • 好的,谢谢,这行得通。虽然我现在有很多 if 语句,只需轻轻一按。是否有另一种方法可以让发射器完全不接收触摸?
    猜你喜欢
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多