我在 SKScene 中有这段代码:
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
var touch: AnyObject = touches.anyObject()
var point = getPoint(touch.locationInNode(self))
var name = NSStringFromCGPoint(point)
for children in self.children {
if (children as SKSpriteNode).name == name {
println("exist!")
}
}
var tempNode = self.childNodeWithName(name)
}
我看到“存在!” 在日志中,因此 children 数组中有一个具有此名称的节点,但 tempNode为nil。该self.childNodeWithName("//" + name)
调用也返回nil。