嗨,我已经绘制了连接图表中节点的 skshapenodes,用于我的视觉 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 个形状。有没有一种方法可以在一次绘制调用中绘制这些形状,因为它们都是相同的,唯一的区别是它们的开始和结束位置。
如果我改用纹理,它会被加载一次,我怎么能改变它的旋转来连接我的所有节点,就像上面一样。
问候,
更新:
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 次,这是为什么呢?