SpriteKit Swift Node Counting Tasks

The simulator shows the node counter that there are 2 nodes. But why? Since there is only one var (ball). Is there a way to create a circle without having double nodes.

class GameScene: SKScene { var ball = SKShapeNode(circleOfRadius: 50) override func didMoveToView(view: SKView) { ball.position = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2) ball.fillColor = SKColor.blackColor() self.addChild(ball) } 
+3
source share
1 answer

This is because SKShapeNode fillColor . Obviously, if either fillColor or strokeColor , each of them requires an additional node and an additional pass to pass. By default, the strokeColor parameter is already set (one node, one pass for the passage), and because of fillColor set additionally, two nodes (and two drawing passes) are required to render the figure.

SKShapeNode in many cases not an effective solution for obvious reasons. One SKShapeNode requires at least one callback. There is an interesting post related to this topic, for example, one or this one .

But still IMO, SKShapeNode should be avoided if this is not the only solution. Just for performance reasons. And in your case, if, for example, you want to have many different types of balls, the solution for the performers will be to use a texture atlas and SKSpriteNode to represent these textures. This way you can display as many balls as you want in a single pass.

Note that a draw is far more important than the number of nodes when it comes to performance. SpriteKit can display hundreds of nodes at 60 frames per second if the number of drawing passes required to render the scene is small.

+2
source

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


All Articles