1

我有一个非常简单的粒子设置,其中雨粒子层位于我的整个 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)
4

1 回答 1

2

使用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'
    }
}
于 2015-11-09T08:06:47.767 回答