2014-09-30 67 views
0

什么是使用Swift迭代场景中所有SKSpriteNode的最佳方法?使用Swift迭代SpriteKit中的所有Sprite节点

+0

可能重复[如何枚举在雪碧套件场景中的所有节点?](http://stackoverflow.com/questions/25749576/how-to-enumerate-all-nodes-in-a-sprite -kit场景) – 2014-09-30 03:53:21

回答

1

如果你的精灵其姓名的属性设置,您可以用枚举关闭:

self.enumerateChildNodesWithName(spriteName) { 
      node, stop in 
      // Do something with node. 
} 
2

我想通了。下面的示例Swift代码。

self.enumerateChildNodesWithName("SomeSprite*", usingBlock: { 
     (node: SKNode!, stop: UnsafeMutablePointer <ObjCBool>) -> Void in 
     // do something with node or stop 
      let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:0.8) 
      node.runAction(SKAction.repeatActionForever(action)) 
     } 
    })