skshapenode添加两个节点?

时间:2015-07-29 11:51:18

标签: ios objective-c sprite-kit skshapenode

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

然而,当它应该是~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;
    }
}

View of web points and nodes to suit.

1 个答案:

答案 0 :(得分:0)

默认情况下,创建SKShapeNode时,strokeColor已设置,并且需要 1个节点+ 1个绘制调用。在您的示例中,您也设置了fillColor,这需要其他节点和额外的平局通行证

在许多情况下,

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

中启用调试标签

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