I have an SCNScene for a 3D game I am building. I have positioned a HUD over this scene using SCNScene.overlaySKScene.
In order to receive taps on my 3D scene, I use a gesture recogniser and hitTest and this works fine.
I am trying to determine the SKSpriteNodes that I have added to the HUD SKScene on taps now. This does not work with the gesture recogniser.
Having looked at the WWDC 2014 Banana sample, I don't think I am doing anything all that different in my use of the alternative touchesBegan method (below).
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
println("touchesBegan")
let scnView = self.view as SCNView
let skScene = scnView.overlaySKScene
let touch: AnyObject? = touches.anyObject()
let p = touch?.locationInNode(skScene)
let touchedNode = skScene.nodeAtPoint(p!)
println("touchedNode \(touchedNode.name)")
super.touchesBegan(touches, withEvent: event)
}
The 2nd println is finding a nil result.
I create by HUD:
scnView.overlaySKScene = SKScene(fileNamed: "HUDScene.sks")
scnView.overlaySKScene.name = "HUD"
scnView.overlaySKScene.delegate = self
I then add a root SKNode to this scene
var hudRoot = SKNode()
And add SKSpriteNodes with userInteractionEnabled=true to this hudRoot.
touchesBegan is being called, but nil is returned when touching the SKSpriteNodes. Interestingly, if I touch outside of the SKSpriteNodes and NOT on any 3D nodes, then it returns the hudRoot node even though that is defaulted to userInteractionEnabled=false.
Now that I have checked my implementation with Apple's own Bananas example, I am without any remaining ideas.