Hi I have drawn skshapenodes connecting the nodes in my graph for my visual a* representation.
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];
}
}
}
There are lots of nodes in my graph and this draws almost 22,000 shapes. Is there a way I can draw these shapes in one draw call, as they are all the same, the only difference is the start and end location of them.
If I used a texture instead, which would be loaded in once, how could I change the rotation of it to join all of my nodes up like above.
Regards,
UPDATE:
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];
I have updated my code to look like the above, this draws one sknode, but it draws 185 times, why is this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…