我试图在 iOS 上的 SceneKit 中移动节点集合,但我遇到了一个神秘错误。到目前为止,这是我的代码:
func renderer(aRenderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) {
let cubes = scene.rootNode.childNodesPassingTest { (node, stop) -> Bool in node.name == "cube" }
for cube in cubes {
cube.position = SCNVector3(x: cube.position.x - 5.0, y: cube.position.y, z: cube.position.z)
}
}
在线 cube.position = ...
我得到 '@lvalue $T7' is not identical to 'CGPoint!'
这个错误是什么意思?另外,如果有更好的方法遍历这些节点,请告诉我!谢谢。
最佳答案
childNodesPassingTest
returns an [AnyObject]
Swift 无法弄清楚 cube
是什么类型(显然它认为 position
属性是 CGPoint!
)。显式地将 cubes
转换为 [SCNNode]
应该可以解决这个问题:
for cube in cubes as [SCNNode] {
cube.position = SCNVector3(x: cube.position.x - 5.0, y: cube.position.y, z: cube.position.z)
}
关于ios - '@lvalue $T 7' is not identical to ' CGPoint!',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26725981/