skshapenode adding two nodes?
Asked Answered
E

1

0

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

-(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.

Emlynne answered 29/7, 2015 at 11:51 Comment(0)
S
0

By default when creating SKShapeNode, strokeColor is already set and it requires 1 node + 1 draw call. In your example you are setting fillColor too, which requires additional node and additional draw pass.

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. Debugging labels can be enabled in view controller (showsDrawCount = YES)

Draw calls are directly affecting on performance in SpriteKit applications and you should try to keep that number as low as possible. One way would be using SKSpriteNode and texture atlases.

Sponson answered 29/7, 2015 at 12:7 Comment(3)
I'm using the shapenode purely just for learning waypoints and pathmaking so I have a visual aid. However, thank you for pointing me to a better performance method. So essentially there's no issue, just the fact that the shapenode requires that many nodes to be created.Emlynne
@Emlynne One of SKShapeNode's main purposes is debugging actually. This can be found in docs. But because SKShapeNode can't be rendered in batches like SKSpriteNode their usage is limited because of performance. Note that node count is not important as draws count when it comes to performance. SpriteKit can render hundreds of nodes at 60fps if number of draws are kept low.Sponson
Thank you ever so much, I wasn't aware of this.Emlynne

© 2022 - 2024 — McMap. All rights reserved.