I'm trying to work out a good way to convert platforms imported from Tiled to collision fixtures in Box2D. The lazy option is to make a square fixture for each tile. This would be quite inefficient.
@hgy29 had a great suggestion:
"Make a two tables of all tile edges: one for horizontal edges and the other for vertical ones. Then go through your wall tiles and increment the correct locations in your two arrays for the four edges of your tiles. In the end you'll get odd numbers for outlines and even numbers for edges not part of the outline"
This would work in most cases, but not in some, like the example below.
Box2D doesn't seem to allow the below boxes as one shape, because the vertices in between the two shapes have no width/height.
Do you have an idea of how to solve this?
Comments
In theory you could also use a chain shape which should also work. I'm not sure what is faster.
I suppose it depends on performance as well. If you need every CPU cycle then you will need to optimize it a lot but going from 6 boxes to 2 is a pretty good saving already
You will also need to think about how large your levels will be and how many physics objects you will be creating, the more you create the more CPU cycles used I guess. Sleeping might alleviate this though.
Oh.. are you procedurally generating these maps?
I'll load each Tiled "chunk" procedurally, so the Tiles content itself is hard coded.
So if the chunk is hardcoded.. why not just create an object layer in tiled and parse that as your box2d objects??
In the example above, the left shape would need to be separated from the single tile.
Any ideas?
1. Go through each tile to determine which type it is (top left corner, top edge, top right corner etc)
2. Start with an edge, find the next edge tile and follow the shape around until the first tile is found and close the shape.
3. Start with a new edge shape that hasn't been previously checked and repeat.
Likes: antix
https://deluxepixel.com
Likes: antix, SinisterSoft
Likes: antix
Dislikes: JuanZambrano