ioscocos2d-iphonecollision-detectiongame-physicsbox2d-iphone

Too many box2d objects makes my game slowly


I am writing a iOS game using Cocos2d. There are a lot of balls(about 7000 objects) in a screen.

When touch the screen, the balls should be exploded in the area, and it should be filled with around balls.

enter image description here

I created a box2d object for each of them and added it in the physics world.

Problems are as follows.

  1. At first, when there is no touch event, screen is filled by 7000 balls, if we start the physics, they are overlapped each other, and there is a gap on top of the screen.

enter image description here

  1. when touch the screen, the game works very slowly.

How can I make the game smoothly?


Solution

  • How can I make the game smoothly?

    Reduce the number of balls. 7000 physics enabled, colliding bodies is pure overkill. Even 700 is a lot.

    In any case there's no quick fix for this. You can try to reduce the number of position & velocity iterations in the box2d world's timestep and do not use collision callback methods (don't set a collision delegate) but that's about it.