2015-03-02 148 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)") 
     } 
    }