SKShapeNode bad Performance

While learning and playing around with Swift and Spritekit i run into an issue:

I can´t seem to create many SKShapeNodes at Runtime. I am trying to fill the Screen with "random" Triangles

(The green Triangle on top is just a "dummy" Triangle moving from the left to the right so i get to see the FPS)

These brown-ish Triangles are SKShapeNodes created like this:

func createTwoFloorTrianglesAtLocation(xPos:CGFloat, yPos:CGFloat, width:CGFloat, height:CGFloat, orientation:Bool) -> [SKShapeNode] {
    
    let path1 = UIBezierPath()
    let path2 = UIBezierPath()
    
    if orientation {
        path1.move(to: CGPoint(x: xPos, y: yPos))
        path1.addLine(to: CGPoint(x: xPos, y: yPos + height))
        path1.addLine(to: CGPoint(x: xPos + width, y: yPos))
        
        path2.move(to: CGPoint(x: xPos + width, y: yPos))
        path2.addLine(to: CGPoint(x: xPos + width, y: yPos + height))
        path2.addLine(to: CGPoint(x: xPos, y: yPos + height))
    } else {
        path1.move(to: CGPoint(x: xPos, y: yPos))
        path1.addLine(to: CGPoint(x: xPos + width, y: yPos + height))
        path1.addLine(to: CGPoint(x: xPos, y: yPos + height))
        
        path2.move(to: CGPoint(x: xPos + width, y: yPos))
        path2.addLine(to: CGPoint(x: xPos, y: yPos))
        path2.addLine(to: CGPoint(x: xPos + width, y: yPos + height))
    }
    
    
    let triangle1 = SKShapeNode(path: path1.cgPath)
    triangle1.fillColor = groundColors[GKRandomSource.sharedRandom().nextInt(upperBound: groundColors.count)]!
    triangle1.name = "colorSprite"
    triangle1.lineWidth = 0.0
    
    let triangle2 = SKShapeNode(path: path2.cgPath)
    triangle2.fillColor = groundColors[GKRandomSource.sharedRandom().nextInt(upperBound: groundColors.count)]!
    triangle2.name = "colorSprite"
    triangle2.lineWidth = 0.0
    
    return [triangle1, triangle2]
}

I add these Triangles calling #addChild(SKNode) to the GameScene.

These Triangles don´t move or anything, they are supposed to disappear later in the Game by "drawing lines" above them.

The Problem is that i get very bad FPS and a high CPU-Usage as well as a high Power-Usage in both the XCode-Simulator and on a real Device (iPhone 13 Pro Max, too). If i reduce the Amount of Triangles it gets better, but i´d like to not do that.

Is there any way to fix this issue?

I also read online (https://stackoverflow.com/questions/23461966/create-an-sktexture-from-an-skshapenode) that some use SKSpriteNode instead of SKShapeNode. But if use the following code to "convert" my ShapeNodes to SpriteNodes before adding them as a Child to the Scene, i see the Node-Counter in the Bottom left is also around 1000ish but there are no Rectangles rendered.

func addNodesToParent(_ stuff:[SKShapeNode]) {
    for n in stuff {
        addChild(SKSpriteNode(texture: self.view?.texture(from: n)))
        //addChild(n)
    }
}

I hope someone has an idea that i can try. Thanks in advance,

Greetings, Nico

Generally speaking, your shapeNode conversion should work.

It's possible that you are experiencing either a layering problem (triangles are behind the main background color - check the zPosition on your spriteNodes), or the conversion of the shapeNode to a texture isn't working as you would expect. I ran into similar problems with shapeNodes in my game.

One thing you could do to troubleshoot is to use Playgrounds to build and convert a shapeNode to a texture, then add it to a scene in the Playground. If that doesn't work (just like in your app), then you have a nice laboratory where you can try different things to figure out what is causing the problem. If I recall correctly, one of the problems that I ran into had to do with positioning of a shapeNode and/or its converted texture. There might be other valid reasons why your triangles aren't showing, but the Playground approach should help you explore various possibilities.

SKShapeNode bad Performance
 
 
Q