skshapenode 添加两个节点?

skshapenode adding two nodes?

我不确定是否存在实施问题或我使用它的方式。

然而,它显示了超过 2,400 个节点,而它应该是 ~ 1,250

-(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;
    }
}

默认情况下,创建 SKShapeNode 时,strokeColor 已经设置,需要 1 个节点 + 1 个绘图调用 。在您的示例中,您也设置了 fillColor,这需要 额外的节点和额外的绘图通道

SKShapeNode 在许多情况下不是高性能解决方案(应谨慎使用),在您的情况下,如果启用调试标签,您可能会看到场景需要大量绘制调用渲染。可以在视图控制器中启用调试标签(showsDrawCount = YES)

绘图调用直接影响 SpriteKit 应用程序的性能,您应该尽量保持该数字尽可能低。一种方法是使用 SKSpriteNode 和纹理图集。