# How to create line segments from tile map outlines

This topic is 1497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there,

i successfully implemented the "Moore Neighborhood" algorythmn to calculate the contours of a tile map, which gives me every tile-outline in clockwise direction. Now i want to create line segments out of it - from edge to edge, but have trouble to figure a algorythmn to solve this. A tile may create/continue two lines in parallel, change directions...

This is what i have:

The black number with the arrow beneath indicates the starting tile including the direction to the next tile.

The colored lines indicates the "tile outline" detected by the algorythmn - i call this "chain" and this goes around clockwise until a tile already visited is found.

A chain have just a list of tile coords in vec2 format, something like this:

chain {

tiles: [Vec2, Vec2, Vec2,...]

};

This is what i somehow want:

Any idea?

Edited by Finalspace

##### Share on other sites

I'm not sure how the "Moore Neighborhood" algorithm helps you here.

I just implemented something similar to what you want. It basically takes a tilemap and generates a contour line for each independent "collection" of tiles (I'm using this to generate a 3d model based off the tile map).

It sounds like you want something slightly different though. What's the logic behind your choices of starting numbers in the above diagram? What's the logic behind joining two or more different colored contours?

##### Share on other sites

I'm not sure how the "Moore Neighborhood" algorithm helps you here.

I just implemented something similar to what you want. It basically takes a tilemap and generates a contour line for each independent "collection" of tiles (I'm using this to generate a 3d model based off the tile map).

It sounds like you want something slightly different though. What's the logic behind your choices of starting numbers in the above diagram? What's the logic behind joining two or more different colored contours?

The algorythmn is just a way to identify the outline tiles but nothing more. All the colored lines in my second picture are defined by every tile a line for 4 directions, but only when there are no neighbors in that direction.

But my overall target is to generate Box2D chain shapes (joined line segments) based on a tile map (solid/not solid). Using boxes for every tile is a bad idea - cause of internal edge isses.

Edited by Finalspace

##### Share on other sites
Have you tried taking your chaining information and walking along the edges until you complete the shape?

Start from the first tile and find a corner that doesn't share a corner with any other. Then move clockwise from one edge to another. Making sure you don't incorporate shared edges?

Then you can connect any contiguous lines that share an axis.

From my phone. Or I'd try to show a picture or something.

##### Share on other sites

Ok i implemented a much better algorythmn which detects all the outlines perfectly... but i still havent figured out a way to traverse the created edges and create the chain-edges / line segments yet.

There are two things which needs to be done i thing to get this thing to work.

First of, the connected edges should be fixed, so that that shared vertices get removed.

Secondly, built a algoryhtmn that traverse the tile in the directions and create line segments out of it.

What i have created is:

- A list of edges. A edge is pair of two indices to the actual vertices + the actual tile position + the edge index (is it a left, right, top, ot bottom edge)

- A list of vertices without any duplicates.

Does someone have an idea?

Here is a image from all the tile edges drawing its vertices (blue) just connected with a red line and displaying each tile position for every edge center.

Greetings Final.

##### Share on other sites

I did it, it works - Now i just need to remove the vertices between the corners and i am done!

The best thing was it was just two more steps in my state-based contour tracing system... :-)

Edited by Finalspace

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633705
• Total Posts
3013464
×