Create box2d physics based on big tiled map?

Hi!

When you have a tiled map that has tile width and height of 32 px and create a much more simpler map like this:

(Plus there is perfect squared and lined objects) - You can easily detect all the tiles that are in use and then add physics around it like this:

BUT a lot of the more “hardcore” games I see tend to use tile width and height around 1px or just very less than 32px, an example:

and then my question is… How are you then supposed to add the physics? I mean if you added a physics box at every single tile here, wouldn’t it take tons of memory. Or should you just switch over to a box2d-editor or how :frowning:
Would love to hear some experiences from building more defined levels! :smile:
Thank you.

Hi.
You can add many static bodies in box2d and the memory and cpu are fine.
You can add some dynamic bodies and no problem with that.
The CONTACTS between bodies is cpu killer.

I have 200 box in my game and 120 edgeShape and 60 fps in low end android device. but when contact number between them is below 50.

It would be a really bad idea to to use a separate box for every tile. From experience I had really large levels in my platformer game. I used the physics editor R.U.B.E to create the levels. So imagine one building in the physics world. You can go round the edge in a dot to dot fashion. Making one large static body.

Here’s an example

You can have a shape of any number of points. I believe you use a linked list of b2edgeshape or something. I can’t remember. Look it up on google. For something complex and non linear you would need a physics editor. There’s a lot of them out there I’m sure there’s one that would support tiled. However for a linear fixed width pattern like a tilemap I bet you could write an algorithm that does it for you.

You can add rectangle, ellipse and polygon objects in Tiled. No need for an extra editor.

Well there you go, if Tiled supports physics exporting and you can find a way to load it in to to Cocos2d-x as a Box2d world then great. I’d recommend against using a box for every tile regardless. Not only is it it adding a lot of overhead compared to using large static shapes that surround sections like walls. But you will also run in to an issue with Box2D known as ghost vertices. This article explains it better than I ever could http://www.iforce2d.net/b2dtut/ghost-vertices Hopefully tiled has a nice solution that groups sections in to large fixtures.

Wow guys thank you so much!!! I will read all the answers very carefully soon(I am very busy atm)