skshapenode添加两个节点? [英] skshapenode adding two nodes?

查看:105
本文介绍了skshapenode添加两个节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定实现方式或使用方式是否有问题.

I'm not sure whether there's an issue with the implementation or the way I'm using it.

但是,当它应该达到约1,250个时,它会显示超过2,400个节点

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

推荐答案

默认情况下,在创建SKShapeNode时,已设置strokeColor,并且需要 1个节点+ 1个绘制调用.在您的示例中,您还设置了fillColor,这需要其他节点和其他绘制过程.

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 在许多情况下不是有效的解决方案(应该谨慎使用),在您的情况下,如果启用调试标签,则可能会看到场景渲染需要很多绘制调用.可以在视图控制器(showsDrawCount = YES)中启用调试标签

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)

绘图调用会直接影响SpriteKit应用程序中的性能,因此您应尽量降低该数量.一种方法是使用 SKSpriteNode 和纹理图集.

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.

这篇关于skshapenode添加两个节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆