1

I have a very simple particle setup where a rain particle layer is on top of my whole SKScene. Now, i just want to touch my buttons and objects underneath that layer. How can i achieve this by still keeping this layer on the highest zPosition. (code Below)

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)
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
keptn
  • 89
  • 8

1 Answers1

2

Use nodesAtPoint: to get all the SKNode located where you touched, including the nodes underneath your particle layer.

For example:

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'
    }
}
WangYudong
  • 4,335
  • 4
  • 32
  • 54
  • okay, thank you, this works. Though I have a lot of if statements now in a single touch. Is there probably another way to keep the emitter from receiving touches at all? – keptn Nov 09 '15 at 13:09