Search code examples
sprite-kitsknode

Reducing number of draw counts (passes) in SpriteKit


I would like to optimize draw counts, but don't know where to start.

Can someone briefly explain ( or point me in the right direction ) which factors affect draws, is there a way to view/debug them and are there any optimization tips? What is the optimal count for draws?

For example, my game loads one texture atlas for whole ui, and uses children nodes as containers for different game menus ( instead of separate scenes). But draw count is 20+ for one screen, and fps drops by 10-15, which is a problem.


Solution

  • Draw counts are the result of needing to layer a scene in the right order, and some nodes can be dependent on the content behind it if they have some transparency for example.

    1: One of the biggest ways to reduce the draw count is to render multiple nodes at once - this can be achieved by adding child nodes you want in the same layer to a parent node. For example, have a parent node called nodeCollection and use addChild() to add multiple nodes to be rendered together to lower the performance hit.

    2: Another thing you can do is set ignoresSiblingOrder to true on SKView, and use zPosition on each node instead - this means that SpriteKit has to do less work as you are more explicit.

    3: Don't use SpriteKit for UI! This is what UIKit is for! You have your SKView which holds your SKScene. SKView is a subclass of UIView, which means that you have it placed in one of your view controllers. All you need to do is add move views or buttons or whatever you want in your view controller on top of your SKView, and you're set!

    For more optimisations I recommend checking out: Hacking with Swift - 15 tips to optimize your SpriteKit game.