This project has moved and is read-only. For the latest updates, please go here.

Best way to combine adjacent tiles.

Topics: Developer Forum
Jun 1, 2011 at 1:56 AM

What is the best way to combine multiple adjacent tiles of the same dimensions into a single polygon? I also want to be able to add and remove tiles from the polygon at runtime.

I thought the marching squares algorithm would work but I can't seem to get it to work. I've tried the Yupeng clipper but that doesn't work either.

Jun 1, 2011 at 3:17 AM

Are the tiles always square and the same size?

If so then a custom converter would be best. I would bet a scanline converter much like the one that's included in the Marching Squares implementation would work quite well. But I wouldn't try reading though that code, it's terrible. Your gonna have to write your own algorithm. Good luck.

Jun 2, 2011 at 2:10 AM

Ok good. I think I have a decent idea for an algorithm, I just didn't want to write one if there was a better more efficient way that already existed in the farseer library.

Jun 14, 2011 at 2:46 AM

Hey, I just found this - looks pretty good for your problem.

Jun 19, 2011 at 4:46 AM

Thanks for the link. I ended up writing my own algorithm that adds each edge of each polygon to a dictionary (minus duplicate edges in the opposite direction), and then picks an edge and walks connected edges using the end point of the current edge as the reference to the start point of the next edge. It works pretty well, here is a video:

My only trouble now is I'm seeing the frame rate stutter when adding bodies to the simulation. Not sure if it is the creation of bodies or the adding them to the world that is causing the stutter.

Jun 21, 2011 at 2:19 AM

Looks something like a Terraria style game. Very cool.