Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

LibGDX hexagonal tilemap getting adjacent tiles

$
0
0

How do I get all adjacent tiles to a hexagonal tile, my tile map is using a staggered co ordinate system with an odd stagger index and I am using libgdx java.

if (x % 2 == 0) {
            hexAdj[0] = new Vector2(x    , y + 1);
            hexAdj[1] = new Vector2(x + 1, y + 1);
            hexAdj[2] = new Vector2(x + 1, y    );
            hexAdj[3] = new Vector2(x    , y - 1);
            hexAdj[4] = new Vector2(x - 1, y    );
            hexAdj[5] = new Vector2(x - 1, y + 1);          
        }else{
            hexAdj[0] = new Vector2(x    , y + 1);
            hexAdj[1] = new Vector2(x + 1, y    );
            hexAdj[2] = new Vector2(x + 1, y - 1);
            hexAdj[3] = new Vector2(x    , y - 1);
            hexAdj[4] = new Vector2(x - 1, y - 1);
            hexAdj[5] = new Vector2(x - 1, y    );
        }

Viewing all articles
Browse latest Browse all 434

Trending Articles