In my SpriteKit game, I have many tile nodes (>100) arranged randomly and I need to be able to detect collisions between the tiles and the character node. To do this, I use SKPhysicsBody.
I find that if I enable SKPhysicsBody code, my frame rate drops to around 40fps, but If I comment out the code, it goes up to 60fps. I guess this is something to do with the engine trying to simulate physics for 100+ nodes each frame... is there a way I can prevent this from happening but still detect collisions between my character and the tiles?
For the tile physics I'm using the following code for my tiles:
self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
self.physicsBody.affectedByGravity = NO;
self.physicsBody.categoryBitMask = WallCategory;
self.physicsBody.collisionBitMask = 0;
self.physicsBody.contactTestBitMask = CharacterCategory;
and for my character:
self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
self.physicsBody.usesPreciseCollisionDetection = YES;
self.physicsBody.restitution = 0;
self.physicsBody.friction = 0;
self.physicsBody.linearDamping = 0;
self.physicsBody.categoryBitMask = CharacterCategory;
self.physicsBody.contactTestBitMask = 0xFFFFFFFF;
self.physicsBody.collisionBitMask = BoundaryCategory;