2
\$\begingroup\$

I am making a civilization style game in Unity. The game uses square tiles and has a 2d sprite style. I am currently implementing a border system like in civ4 where a line is drawn around you civilization's borders, but I cannot find a way to create the correct sprites to draw the border.

My first thought was to have a sprite corresponding to each neighbor, the sprite would toggle on if the tile it is over is in the bordered area and the corresponding neighbor is not. This would work but It would require 8 (one for each neighbor) sprite renderers per tile and I assume that would be pretty inefficient.

I thought of making a separate sprite for each configuration to cut it down to one sprite renderer per tile but that would require 2^8 sprites which just is not feasible.

I also thought that maybe I should stick to the first idea but only instantiate or move sprite renderers to where they are needed which would greatly reduce the amount of sprite renderers used at once. This seems like my best option but it seems unnesicarily complicated and still pretty inefficient.

I do not know of any simple way to dynamicaly draw sprites to fit a pattern, so it seems I am stuck with one of these solutions. Does anyone know of a better way to handle this?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You might find this survey of tileset patterns useful. With a few constraints or sub-tile units, you can cut down the number of cases you need to author quite dramatically. \$\endgroup\$
    – DMGregory
    Commented Dec 9, 2017 at 19:27
  • \$\begingroup\$ Are you using Unity 2017.2 or newer? \$\endgroup\$
    – Stephan
    Commented Dec 14, 2017 at 15:48

1 Answer 1

1
\$\begingroup\$

This answer applies to Unity2017.2 or newer, utilizing the Grid/Tilemap functionality included.

The Grid supports multiple layers by adding a new Tilemap for each draw layer you want in your tiles.

For Civ-like borders, add a Tilemap to the Grid called Borders. Then take a look at the Scriptable Tile Tech Demos, particularly the TerrainTile. Simply use corresponding sprites, paint them to the layer, and voila: Civ-like borders.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .