一次绘制多个skshapenode?

您好我已经绘制skhapenodes连接我的graphics中的节点为我的视觉a *表示。

for(int x=0; x<64; x++) { for(int y=0; y<48; y++) { PathFindingNode *node = [[gridToDraw objectAtIndex:x] objectAtIndex:y]; for(int i=0; i< node.connections.count; i++) { PathFindingNode *neighbor = [node.connections objectAtIndex:i]; SKShapeNode *line = [SKShapeNode node]; CGMutablePathRef pathToDraw = CGPathCreateMutable(); CGPathMoveToPoint(pathToDraw, NULL, node.position.x, node.position.y); CGPathAddLineToPoint(pathToDraw, NULL, neighbor.position.x, neighbor.position.y); line.path = pathToDraw; line.lineWidth = 0.1f; [line setStrokeColor:[UIColor blueColor]]; line.alpha = 0.1f; [self addChild:line]; } } } 

在我的图中有很多的节点,这将得到近22,000个形状。 有没有一种方法可以在一次绘制调用中绘制这些形状,因为它们都是相同的,唯一的区别是它们的开始和结束位置。

如果我使用了一个纹理,而这个纹理会被加载一次,我怎么能改变它的旋转来join我的所有节点,就像上面那样。

问候,

更新:

 SKShapeNode *line = [SKShapeNode node]; CGMutablePathRef pathToDraw = CGPathCreateMutable(); for(int x=0; x<64; x++) { for(int y=0; y<48; y++) { PathFindingNode *node = [[gridToDraw objectAtIndex:x] objectAtIndex:y]; for(int i=0; i< node.connections.count; i++) { PathFindingNode *neighbor = [node.connections objectAtIndex:i]; CGPathMoveToPoint(pathToDraw, NULL, node.position.x, node.position.y); CGPathAddLineToPoint(pathToDraw, NULL, neighbor.position.x, neighbor.position.y); } } } line.path = pathToDraw; line.lineWidth = 0.1f; [line setStrokeColor:[UIColor blueColor]]; line.alpha = 0.1f; [self addChild:line]; 

我已经更新了我的代码,看起来像上面,这绘制了一个sknode,但它绘制了185次,这是为什么?

我昨天也想回答这个问题,但是消失了。

您可以创build一个path,并使用CGPathAddPath将所有东西绘制为一个SKShapeNodeCGPathAddPath随时合并path。

这是一个例子:

 SKEffectNode *effectNode = [[SKEffectNode alloc]init]; SKShapeNode *shape = [[SKShapeNode alloc] init]; CGMutablePathRef myPath = CGPathCreateMutable(); CGPathAddArc(myPath, NULL, 0,0, 15, 0, M_PI*2, YES); CGMutablePathRef pathTwo = CGPathCreateMutable(); CGPathAddArc(pathTwo, NULL, 50,0, 15, 0, M_PI*2, YES); CGPathAddPath(myPath, NULL, pathTwo); CGMutablePathRef pathThree = CGPathCreateMutable(); CGPathAddArc(pathThree, NULL, 100,0, 15, 0, M_PI*2, YES); CGPathAddPath(myPath, NULL, pathThree); shape.path = myPath; [effectNode addChild:shape]; [self addChild:effectNode]; effectNode.shouldRasterize = YES; // if you don't rasterize it's horrifically slow. 

这只是一个如何合并不同path的例子来创build一个SKShapeNode ,其中包含所有您正在寻找的视觉元素。 你需要把这个概念应用到你的代码中。

我将生成的SKShapeNode添加到SKEffectNode以便我可以使用shouldRasterize属性来caching形状,否则帧率将会非常糟糕。