Spritekit performance/fps drop after having approx 20-30 monster nodes in view.

My FPS drops to about 55 fps once approximately 20 monsters in my game are in the main view. The monsters normally just have a walking animation. There are also some tree spritenodes with physics bodies attached so the player can't run into them. What are some of the main reasons for FPS drop? When I get to about 40 monster animating monster sprites in the view the fps drops to around 40-45.


***EDIT***


Alright so I figured one thing out. What I was doing to reduce memory was when a monster came out of the view, I would remove the node and store it's point + monster type in a dictionary. Then when that "point" would later return to just outside the border of the view, I would replace the point in the dictionary with the corresponding monster node.


For some reason, removing and adding the nodes uses more memory and was making my game a little choppy from reduced FPS (48-55 FPS was laggy). I tried a new method where I just load all the monster nodes at startup without replacing them and that seemed to use less memory somehow. My FPS would still drop to about 55 when I had 20 or so monsters on the screen, but the gameplay was smooth with little or no "choppiness".

I've found in the past that liberal use of enumerateChildNodesWithName is not good, so if you use that in the scene Update for child nodes of the scene it will quickly eat CPU. As ever, using node trees, caching and pooling stuff will allow you to keep high frame rates. *If* you do use enumerateChildNodesWithName multiple times in a scene frame, consider just doing a standard loop around the children of the scene right at the top of the Update and putting stuff in keyed dictionaries for lookup elsewhere. But, as I say, good use of node trees and caching should mean you don't have to do it at all.

This is not true, I build a game with 30 nodes and 200% (cpu usage) in a real device (iphone6S), and I m not use childs with name. I thinks sprite kit its a really bad framework for build games. Its imposible build a nice game with less than 25 nodes. I think its the worst framework how I ever seen.

I'm currently using enumerateChildNodesWithName in Update to remove enemies from the scene when they go off screen (enemy.position.x<0), after seeing your comment this clearly isnt the best move-- especially if I have multiple enemy types I have to check for. What would you suggest instead? Thanks a lot.

You might want to post some code, because I think you may be doing it wrong. I've got 100~200 nodes, multple scrolling background layers, physics and can get 60fps on an iPad 2 and 3 with ~50 to 70% cpu. Absolutely no problems with an iPhone 6S.


There's plenty of issues with SpriteKit, especially with regard to audio and physics edge cases, but I don't see any big problems with graphics throughput.

Are you using texture atlases? Are you saving the textures for later use and sharing them between sprites? Also, you mention that you are using physics bodies. How many, and are they set up correctly? There's lots of places that could be cause a performance hit. Perhaps you can post some code.


Cheers.

I agree, I have had over 1000 nodes on the screen with an iPhone 5 before I noticed any kind of lag, definately nothing wrong with the API

enumerateChildNodesWithName is a slow method, you are doing string checks on a list of nodes. Not a good idea. If your issue is determining when a node goes off screen, then save a list of all nodes that are on screen, and iterate over that, or do the faster method, and subclass the nodes, and override the position property didSet method, this way you are not looping through all nodes on your update, and instead remove when needed

Spritekit performance/fps drop after having approx 20-30 monster nodes in view.
 
 
Q