for(SKNode * nodes in nodes) in swift
for(SKNode * node in nodes) in swift
我是 swift 的新手,正在学习
我用
“ for(SKNode * node in nodes) ”
选择名称在 objective-C 中但在 swift 中的特定节点,我需要一些帮助才能做到这一点。提前致谢
在SWIFT
for node in nodes {
}
这是一个在 swift 中使用 "for" 循环的简单示例:
let arrStrings = ["one","two","three","four"]
for str in arrStrings
{
if str=="two"
{
println("\(str)")
}
}
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* node)
let nodes = self.nodesAtPoint(touchLocation) as [SKNode]
我是 swift 的新手,正在学习 我用 “ for(SKNode * node in nodes) ” 选择名称在 objective-C 中但在 swift 中的特定节点,我需要一些帮助才能做到这一点。提前致谢
在SWIFT
for node in nodes {
}
这是一个在 swift 中使用 "for" 循环的简单示例:
let arrStrings = ["one","two","three","four"]
for str in arrStrings
{
if str=="two"
{
println("\(str)")
}
}
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* node)let nodes = self.nodesAtPoint(touchLocation) as [SKNode]