ios - SKCameraNode 函数 containsNode() 和 containedNodeSet() 没有按预期工作

标签 ios swift sknode

我试图在 iOS 9.0 中使用新的 SKCameraNode,但我遇到相机总是为 containsNode() 返回 false,为 containedNodeSet() 返回一个空集。

为了测试,我使用 SpriteKit 模板创建了一个空项目并添加了一个摄像头。我唯一改变的是在 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 */  
    }  
}  

日志中的输出是:

false
[]

既然它是场景中的一个节点(并且清晰可见),它不应该在集合中返回 true 和 myLabel 吗? 我做错了什么吗?感谢您的帮助!

就在有人说模拟器不准确之前,我正在 iPad mini 2 上运行它。 :P

最佳答案

这似乎是一个错误,Apple 已在 iOS 9 beta 3 中识别出它。我将编辑我的答案以确认它是否有效。

编辑:有效!更新您的开发设备,它应该可以工作。

关于ios - SKCameraNode 函数 containsNode() 和 containedNodeSet() 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31275235/

相关文章:

ios - 在其他平台上使用 iOS GameKit 的 "Bluetooth Bonjour"

ios - 模态呈现时白色闪烁动画

ios - 为什么 NSDecimalNumber.notANumber.intValue 返回 9?

ios - swift:声明公共(public)变量

Swift + SpriteKit - 即使按钮不可见也可以点击

swift - 如何在每次触摸SKNode时加1点

iphone - 创建一个 UINavigationController 以在没有 Interface Builder 的 UITableViewController 中使用

iPhone:Retina 显示屏将字体写入 UIImage

ios - iOS swift 中变量值变空

ios - Spritekit SkNodes 相交的矩形/多边形