How to apply wall objects to tiles efficiently

by Dave   Last Updated May 04, 2017 02:13 AM

So i have a tile grid with a tile mask method which calculates the value of each tile like so:

        for (int i = 0; i < Tile_List.Count; i++)
            int value = 0;
            Tile tile = Tile_List[i];
            if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.left + Vector3.forward))
                value += 1;
            if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.forward))
                value += 2;
            if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.forward + Vector3.right))
                value += 4;
            if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.left))
                value += 8;
            if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.right))
                value += 16;
            if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.back + Vector3.right))
                value += 32;
            if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.back))
                value += 64;
            if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.back + Vector3.left))
                value += 128;


The problem i now have is creating the objects for the tiles is a huge if/else if block of code to check for every combination of tile value which just seems pretty inelegant. Given the values range from 0 - 255 theres a lot of numbers that end up needing the same visuals.

I am using 3D so a sprite sheet isn't an option here. But i am trying to find a way to simplify checking each tile's mask values grouping the same values together since some numbers require the same walls anyway, that way I know what wall objects i need, I can't find code examples beyond how to set the tile mask values which is kind of frustrating to work out how to make the next step as simple as possible.

Related Questions

Implementing RPG Maker Auto Tiling

Updated April 13, 2015 00:05 AM

Paint game level algorithm

Updated April 10, 2015 00:05 AM