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
Would love to hear some experiences from building more defined levels!
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.
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.
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.