Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit max number of nodes

Tags:

ios

sprite-kit

I am creating a SpriteKit game with a tiled map. Each tile is an SKSprite node. When I have about 800 tiles, there are no problems. But if I try to increase the size of the map to around 2000 tiles, my FPS goes from 60 to 20. The number of tile nodes on the screen doesn't change (about 80), just the number of nodes off-screen. Any ideas of what could be causing this, or how to remedy it?

like image 239
user1007895 Avatar asked Oct 16 '13 18:10

user1007895


People also ask

What is a node in SpriteKit?

Nodes are the fundamental building blocks of SpriteKit, and SKNode is the base class of all nodes. All of your onscreen assets will be an SKNode or a subclass thereof. SKNode s by themselves do not provide any visual content, however.

Is SpriteKit still used?

SpriteKit is definitely not dead and still supported by Apple. However it has been overshadowed by other technologies from Apple such as AR, Metal, etc. Additionally, it's not portable to other platforms (unlike Unity).

Does SpriteKit use Metal?

SceneKit, SpriteKit and Core Image all have some integration with Metal shaders and Metal rendering. There may be times when you don't want to write a full-blown 3D Metal app, but you want to take advantage of SceneKit.

What can SpriteKit do?

The SpriteKit framework makes it easy to create high-performance, battery-efficient 2D games. With support for custom OpenGL ES shaders and lighting, integration with SceneKit, and advanced new physics effects and animations, you can add force fields, detect collisions, and generate new lighting effects in your games.


Video Answer


1 Answers

There doesn't appear to be a defined max number of nodes. It really depends on the amount of available free memory on your device. For example consider the following code:

int NODE_LIMIT = 375000
....

    for (int i = 0; i<NODE_LIMIT; i++) {
        SKNode *node = [SKNode node];
        [self addChild:node];
    }

I can create 375000 nodes in my sprite kit game. But as I increase the number above that, my device runs out of memory. The amount of free memory on your device will vary depending on a number of factors. As mentioned in the comments, the reason your frame rate slows down, is because the physics simulation runs even for nodes which are not visible on screen.

To maintain a high frame rate, get rid of physics bodies which are not visible, or which do not need to be simulated every frame. You could do this by adding sprites / physics bodies only when they are in the viewable part of the screen, and removing them when they are not.

like image 122
Rahul Iyer Avatar answered Oct 14 '22 16:10

Rahul Iyer