Search code examples
iosswiftsprite-kitframe-ratesktilemapnode

Troubles with performance issues in SpriteKit platformer game


I'm experiencing some lag for the first time in developing a platformer game for iOS. I'm relatively new to development, so I'm assuming I'm already making mistakes that can slow my game down.

I just have a few questions that I'm confused about.

  1. I'm building a platformer so I will have nodes outside the scenes camera view at times. Should I be looping through all nodes and removing them from the scene if not? Would this help with performance, or does SpriteKit automatically do this with the skcameranode?

  2. I'm wanting to build sort of like an open world kind of feel, so some levels could be large. I have a lot of 128x128 tiles that I use with tilemapnodes for the foreground. The stuff like the ground, dirt, platforms, etc that the player will interact with. I also have 5 layers of parallax'ed backgrounds that are 512x512 tiles, each with their own tilemapnode. My question is about these huge levels. Should I be breaking up these tilemapnodes into sections? Would this help you performance?

  3. Last question, So the 128x128 tiles are really 256x256. I just scaled down the tilemapnode. I created a huge tilemapnode for the foreground and made the ground and floor and a few hills with this one map node. When I would move the player to an area that was dense with nodes, it would lag down to 45-55 fps. when away from this dense area, it would go back to 60 fps; leads me to believe that SpriteKit handles the question 1 thing. Anyways, rather than creating the images in 256x256 and scaling down when needed, will it help performance creating separate images in different sizes rather than using the scaling option? (I am using the 1,2,3x images for every image, if that matters)

Thanks for any help.


Solution

  • Here are some general tips for performance, as mentioned in the comments: