dev*_*546 1 ios ios7 sprite-kit skshapenode
嗨,我为我的视觉a *表示绘制了skshapenodes连接图中的节点。
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];
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的图中有很多节点,它绘制了将近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];
Run Code Online (Sandbox Code Playgroud)
我已经更新了代码,使代码看起来像上面一样,这画了一个sknode,但是画了185次,为什么呢?
我昨天打算就类似的问题回答这个问题,但是它消失了。
您可以创建一条路径,并SKShapeNode使用一条路径CGPathAddPath合并所有内容,从而绘制所有内容。
这是一个例子:
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.
Run Code Online (Sandbox Code Playgroud)
这只是一个示例,说明如何合并不同的路径以创建SKShapeNode包含您要查找的所有视觉元素的路径。您需要将此概念应用于代码。
我将结果添加SKShapeNode到中,SKEffectNode以便可以利用该shouldRasterize属性来缓存形状,否则您的帧速率将很糟糕。
| 归档时间: |
|
| 查看次数: |
2712 次 |
| 最近记录: |