I was trying to use the new SKCameraNode in iOS 9.0, but I encountered that the camera is always returning false for containsNode() and an empty set for containedNodeSet().
Just to test, I created an empty project with the SpriteKit template and added a camera. The only thing I changed was in GameScene:
class GameScene: SKScene {
let myLabel = SKLabelNode(fontNamed:"Chalkduster")
override func didMoveToView(view: SKView) {
/ Setup your scene here */
myLabel.text = "Hello, World!";
myLabel.fontSize = 65;
myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));
let camera = SKCameraNode()
camera.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
self.addChild(camera)
self.addChild(myLabel)
self.camera = camera
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/ Called when a touch begins */
for touch in touches {
let location = touch.locationInNode(self)
print(camera!.containsNode(myLabel))
print(camera!.containedNodeSet())
}
}
override func update(currentTime: CFTimeInterval) {
/ Called before each frame is rendered */
}
}
The output in the log is:
false
[]
Shouldn't it be returning true and myLabel in the set since it's a node in the scene (and clearly visible)? Is there something I'm doing wrong? Any help is appreciated!
Just before someone says the simulator isn't accurate, I'm running this on an iPad mini 2. :P
It appears this was a bug and Apple has recognized it in iOS 9 beta 3. I will edit my answer to confirm if it works.
EDIT: It works! Update your development device and it should work.