Search code examples
swiftsprite-kitskspritenode

High SpriteKit draw count with SKSpriteNode & texture atlas


I have a SpriteKit game in which there are balls that bounce around. Despite using a texture atlas (a .spriteatlas folder located in my .xcassets folder), I'm getting 2 draw calls for each ball.

Some facts:

  1. The balls are SKSpriteNode's.
  2. Each ball is a parent node that has a child node (an overlay with the opposite rotation of the ball to provide the illusion of lighting/shadow). So, we're talking about 2 nodes for each ball.
  3. The balls' textures are preloaded up front and stored in memory via textureNamed(_:).
  4. I have set view.ignoresSiblingOrder = true.
  5. There is no SpriteKit background image that would make the balls render on top of another node; the background is transparent. So, the balls do not overlap other content.
  6. zPosition is not set -- not on the parent and not on the child.

Based on what I've learned about how the scene is rendered, I would expect to see all the parent nodes rendered in a single pass, with additional passes for the child nodes (though, even that is suspicious since I have ignoresSiblingOrder set to true).

What am I not understanding, here? Why does my draw count increase so drastically as more balls are added to the scene?

Thank you!

UPDATE:

If I don't add the child nodes to the balls, the draw count for the balls is 1 regardless of how many balls there are. So, it's definitely an issue with the child nodes, not the parents.


Solution

  • I solved the problem by setting zPosition to the same value on both the parent and child.

    parentNode.zPosition = 1.0
    childNode.zPosition = 1.0
    

    There are now a total of 2 draws for the balls regardless of how many balls there are.