简体   繁体   English

skshapenode添加两个节点?

[英]skshapenode adding two nodes?

I'm not sure whether there's an issue with the implementation or the way I'm using it. 我不确定实现方式或使用方式是否有问题。

However, it's presenting over 2,400 nodes when it should be ~ 1,250 但是,当大约应该有1,250个节点时,它会显示超过2,400个节点

-(void)drawWeb  {
    //get distance of 50 across

    int distanceMargin = _background.frame.size.width/50;

    NSLog(@"%i", distanceMargin);

    __block int xCounter = distanceMargin;
    __block int yCounter = 0;

    NSArray *alphabet = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];

    for (int i = 0; i < 25; i++) {

        for (int j = 0; j < 50; j++) {
            webPoint *shape = [webPoint shapeNodeWithCircleOfRadius:1];
            shape.position = CGPointMake(xCounter, _background.frame.size.height - yCounter);
            shape.fillColor = [UIColor blackColor];
            shape.alpha = 1;
            shape.webPoint = [NSString stringWithFormat:@"%@%i", alphabet[i], j];
            shape.positionX = xCounter;
            shape.positionY = yCounter;
            shape.name = @"webPoint";
            [_background addChild:shape];

            xCounter = xCounter + distanceMargin;
        }

        xCounter = distanceMargin;

        yCounter = yCounter + distanceMargin;
    }
}

Web点和适合的节点的视图。

By default when creating SKShapeNode, strokeColor is already set and it requires 1 node + 1 draw call . 默认情况下,创建SKShapeNode时, strokeColor已设置,并且需要1个节点+ 1个draw call In your example you are setting fillColor too, which requires additional node and additional draw pass . 在您的示例中,您还设置了fillColor ,这需要额外的节点和额外的绘制过程

SKShapeNode is not performant solution in many cases (it should be used sparingly), and in your case, if you enable debugging labels you will probably see that there are a lot of draw calls required for scene rendering. 在许多情况下, SKShapeNode并不是高性能的解决方案(应谨慎使用),并且在您的情况下,如果启用调试标签,则可能会看到场景渲染需要很多绘制调用。 Debugging labels can be enabled in view controller ( showsDrawCount = YES ) 可以在视图控制器中启用调试标签( showsDrawCount = YES

Draw calls are directly affecting on performance in SpriteKit applications and you should try to keep that number as low as possible. 绘图调用直接影响SpriteKit应用程序中的性能,因此您应尽量降低该数字。 One way would be using SKSpriteNode and texture atlases. 一种方法是使用SKSpriteNode和纹理地图集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM