Search code examples
sprite-kitskshapenode

How to increase FPS in spritekit game with lot of SKShapeNodes?


I need a suggestion. I am making a game with lots of SKShapeNodes. So my FPS is about 18. Has anybody suggestions about how to increase FPS in games like this? Amount of SKShapeNode in the full game scene are 220.


Solution

  • SKShapeNode is rather performance intensive because SpriteKit is rasterising (computing the pixels of your shape) every frame instead of calculating it once and than reusing it.

    The two options I see are :

    • Creating SKTexture(s) object(s) with your shape nodes, and than displaying those textures with SKSpriteNode instead of displaying directly your SKShapeNode objects.
    • Making some/all of your SKShapeNode objects children of SKEffectNode and set its shouldRasterize property to true, what it means is that it will rasterise the SKEffectNode children once, cache what has been rendered and reuse it while there is no change.

    What you should use depends on what you are trying to achieve, is the shape of those nodes changing over time ? Are those shapes moving around ? Is it all of them changing/moving or only some of them ?