新手快速学习 我用 “for(节点中的SKNode *节点)” 用于在Objective-C中选择其名称的特定节点,但是在swift中我需要一些帮助才能做到这一点。提前致谢
答案 0 :(得分:1)
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
let nodes = self.nodesAtPoint(touchLocation) as [SKNode]
for node in nodes {
if let nodeName = node.name {
if nodeName == "myNodeName" {
println("node tapped")
}
}
}
}
要检查节点是否被点击,请使用for循环进行迭代。循环浏览SKNodes,并检查节点名称是否匹配。区别在于我们不是(SkNode *节点):
let nodes = self.nodesAtPoint(touchLocation) as [SKNode]
答案 1 :(得分:0)
for node in nodes {
}
答案 2 :(得分:0)
这是一个在swift中使用“for”循环的简单示例:
let arrStrings = ["one","two","three","four"]
for str in arrStrings
{
if str=="two"
{
println("\(str)")
}
}