2015-03-02 100 views
-3

AM(SKNode *在节点的节点)新迅速和学习 我用 “为(SKNode *在节点的节点)” 用于在Objective-C与它的名字中选择特定的节点,但在迅疾我需要一些帮助来做到这一点。在此先感谢在迅速

在SWIFT
+4

只是阅读文档:For循环(https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language /ControlFlow.html#//apple_ref/doc/uid/TP40014097-CH9-ID121) – Antonio 2015-03-02 10:12:00

回答

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") 
        } 
       } 
      } 
     } 

要检查如果一个节点被窃听,与迭代循环。循环浏览SKNodes,并检查节点名称是否匹配。不同的是,代替(SkNode *节点),我们有:

let nodes = self.nodesAtPoint(touchLocation) as [SKNode] 
0

for node in nodes { 

} 
0

这里是迅速使用 “for” 循环一个简单的例子:

let arrStrings = ["one","two","three","four"] 

    for str in arrStrings 
    { 
     if str=="two" 
     { 
     println("\(str)") 
     } 
    }