【发布时间】:2015-06-08 07:56:39
【问题描述】:
如果我使用下面的方法,我可以遍历我的 SKNode 父级中的子对象,并且可以很好地获取场景中的位置
for child in platformGroup.children {
let posInScene = self.convertPoint(child.position, fromNode: platformGroup)
println("Pos in scene \(posInScene)")
}
当我尝试从节点中的第一个或最后一个子节点获取位置属性时,我得到一个错误。
let lastPlatPos = self.convertPoint(platformGroup.children.last?.position! , fromNode: platformGroup)
println(lastPlatPos.x)
错误:可选类型“CGPoint”的值未解包,您的意思是 采用 '!'还是“?”?
我在这里错过了什么?
即使我把它包装起来,我也会得到同样的错误:
if let lastPlatPos = self.convertPoint(platformGroup.children.last?.position! , fromNode: platformGroup) {
println(lastPlatPos.x)
}
【问题讨论】:
标签: swift sprite-kit sknode