Handling Tiled Backgrounds (ie 1000s of immovable squares)

Hi,

I've just started looking at box2d and I was wondering about how to best handle a game like Super Mario, where the background contains hundreds of immovable tiles that the player and other objects can collide against. Would having that many physical objects have a huge hit on performance?

Also, how would you setup an object like a background tile to be immoveable?

thanks!
DJCC
You can create fat columns of tiles as static bodies with multiple shapes. To keep memory requirements down, you can load/unload the static bodies as needed. Box2D's broad-phase mechanism should keep performance reasonable. You can create static bodies by attaching only shapes with zero density.
Hi,

By "fat columns of tiles" do you mean columns with the width of multiple tiles?

Something like this:

a "fat column" with a width of four tiles.

[][][][]
[][][][] <- each tile is a shape?
[][][][]
[][][][]
[][][][]
[][][][]

If I get the nomenclature right, would that be one body with multiple shapes?

Another question, if I didn't get the first one totally wrong: would that mean that long, horizontal platforms wouldn't be as efficient? Would they need to be broken up into smaller pieces?
Your picture is correct. In general, you should use as few shapes as possible. So long horizontal platforms could be a single box shape.
yeah, building on Erin's reponse. If you have a Mario-style platform that is six blocks long, use a single long rectangle to model it on the physics "layer", but render six tiles horizontally in your graphics layer. You don't need to literally represent everything in your visual layer in your physics model.
Also, some tiles wouldn't need a physics counter-part either (ex. ones inside terrain that can never be reached). Programming might get a little messy trying to separate the two though. You could probably come up with an algorithm to compute the largest possible rectangle to fit your tiles.

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