Handling a large number of static objects (tiles)

I'm creating a game similar to this one:
http://getcontinuum.com/screenshots/eg2.png (screenshot)

The map is made up of a sparse set of individual tiles filling approx 1000x1000 set of static (unmoveable) tiles.
My problem is i can't add any more than 512 "bodys" to the Box2D engine (each tile is a body), i hit a hard limit.

Is there another way to add static information to the engine. The tiles will never move, and i want collisions with them to all behave exactly the same. Is Box2D even a good choice for this problem?

I get the feeling im doing something horribly wrong here but can't work out what :/

I'm not sure if i've described my problem terribly well, so if you want me to add anything please let me know
Can't you just merge your static tiles into larger objects?

For example:
You have a floor, each tile is 32px x 32px. You need 20 tiles to fill 640px. Here you can just make one big rectangle instead of 20 boxes.

btw: You don't need multiple bodies for multiple tiles / shapes. A body can hold many shapes.
I think the neatest solution would be to group your tiles up into 'clusters' of tiles that have neighbour tiles, then trace the edge of each of these clusters, creating an edge chain shape for each cluster.
Thank you for your replies 🙂

BigRob wrote:
Can't you just merge your static tiles into larger objects?

For example:
You have a floor, each tile is 32px x 32px. You need 20 tiles to fill 640px. Here you can just make one big rectangle instead of 20 boxes.

btw: You don't need multiple bodies for multiple tiles / shapes. A body can hold many shapes.

Its not really practical given the design of many levels is lots of tiles spread out over a large area. Evenwith the edge chain optimisation (as suggested ) i would easily have over 512 sepeate shapes. Most of the level is just empty space. (please look at the screenshot http://www.getcontinuum.com/screenshots/tw.png (and the radar image in it) )

Would you be able to go into more detail about how you get a body to hold more than one shape, and how you position the shapes, i read something about this in the manual but im struggling to understand from the documentation how you would do it in practice.
Hi,

i found this on Emanuele Feronato's site. He uses six or seven shapes for one ground body.

Code:
// add the ground //
         bodyDef = new b2BodyDef();
         bodyDef.position.Set(0, 0.5);

         boxDef = new b2PolygonDef();
         boxDef.SetAsBox(50, 0.5);
         boxDef.friction = 1;
         boxDef.density = 0;

         body = world.CreateBody(bodyDef);
         body.CreateShape(boxDef);

         boxDef.SetAsOrientedBox(1, 2, new b2Vec2(-50, 0.5), 0);
         body.CreateShape(boxDef);

         boxDef.SetAsOrientedBox(1, 2, new b2Vec2(50, 0.5), 0);
         body.CreateShape(boxDef);

         boxDef.SetAsOrientedBox(3, 0.5, new b2Vec2(5, 1.5), Math.PI/4);
         body.CreateShape(boxDef);

         boxDef.SetAsOrientedBox(3, 0.5, new b2Vec2(3.5, 1), Math.PI/8);
         body.CreateShape(boxDef);

         boxDef.SetAsOrientedBox(3, 0.5, new b2Vec2(9, 1.5), -Math.PI/4);
         body.CreateShape(boxDef);

         boxDef.SetAsOrientedBox(3, 0.5, new b2Vec2(10.5, 1), -Math.PI/8);
         body.CreateShape(boxDef);
Box2D's hard limits can be changed. Look in b2Settings.h. The defaults are conservative, so you ought to be able to increase them without much worry.

Adding multiple shapes to one body is desirable, but it won't help against the limits you are seeing.

Original thread: https://box2d.org/forum/viewtopic.php?t=3117