Low-performance Sprite Kit with multiple nodes in one place

I set up a scene with 200 sprite instances and placed them randomly on the screen as follows:

for(int i = 0; i < bubbleCount; i++) { CGSize size = [self getRandomSize]; SKSpriteNode *bubble = [SKSpriteNode spriteNodeWithTexture:texture size:size]; bubble.anchorPoint = CGPointMake(0.5, 0.5); bubble.position = [self getRandomPosition]; bubble.name = BUBBLE; SKPhysicsBody *physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:size.width/2]; physicsBody.dynamic = YES; physicsBody.affectedByGravity = NO; physicsBody.allowsRotation = NO; physicsBody.categoryBitMask = 0; physicsBody.contactTestBitMask = 0; physicsBody.collisionBitMask = 0; bubble.physicsBody = physicsBody; [self addChild:bubble]; } 

While the nodes are kept at a distance from each other, I get a stable 60 frames per second. When I use force so that the nodes begin to move towards the center of the scene and overlap each other, the performance drops sharply to 2-3 frames per second. I think this is due to collision detection rather than rendering (if I initialize a physical body with a large radius, performance is very low already at the beginning). I set the masks for categories, contacts and collisions to 0, but this does not help.

+7
ios collision-detection sprite-kit
source share
1 answer

It’s best to pre-render this scenario instead of forcing the iPhone to go through 200 collision detection bodies, which will undoubtedly cause stress.

0
source share

All Articles