Skshapenode adds two nodes?

I am not sure if there is a problem with the implementation or the way I use it.

However, it represents over 2400 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 web points and sites as required.

0
source share
1 answer

By default, when creating SKShapeNode, strokeColor already set, and this requires 1 node + 1 to draw a call . In your example, you also set fillColor , which requires an extra node and an extra draw draw .

SKShapeNode is in many cases not an effective solution (it should be used sparingly), and in your case, if you enable debugging tags, you will probably see that many scene calls are required to render the scene. Debugging labels can be enabled in the controller view ( showsDrawCount = YES )

Draw calls directly affect performance in SpriteKit applications, and you should try to keep this number as low as possible. One way: SKSpriteNode and texture atlases.

0
source

Source: https://habr.com/ru/post/1261686/


All Articles